Announcement

Collapse
No announcement yet.

PS commands are not recognized in batch file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PS commands are not recognized in batch file

    I renamed txt file with PS commands to bat

    Then in elevated PS prompt typed .\file_name

    after each command in my batch I received : not recognized.

    Works fine when running one by one in the same prompt
    what I am missing?

    Thx.

    Commands in batch:


    Set-ExecutionPolicy RemoteSigned -Scope Process -Force
    Import-Module AppVClient
    Get-AppvClientPackage
    Get-AppvClientConnectionGroup
    Get-AppvPublishingServer
    "When you hit a wrong note it's the next note that makes it good or bad". Miles Davis

  • #2
    Re: PS commands are not recognized in batch file

    Try renaming the file to have a ".ps1" extension. You can't use PowerShell commands in regular batch files (with .bat or .cmd extensions).

    Comment


    • #3
      Re: PS commands are not recognized in batch file

      Ser Olmy,

      you are right!

      I used the related answer for someone's question on web an the guy mention .bat

      Save your file as a standard batch file.
      Stating the obvious but ensure you have the correct extension so if for example you use notepad, ensure you save with the extension .bat and not .bat.txt. Show file extensions in explorer to see this.
      Not so obvious is to ensure you file is saved as US-ASCII (Visual Studio) or ANSI (Notepad) and NOT Unicode.
      Then, in PowerShell, simply type...
      .\YourBatchFileName.bat The .\ is important here. It assumes you want to run a file in the current directory.
      Hope this is helpful.
      "When you hit a wrong note it's the next note that makes it good or bad". Miles Davis

      Comment

      Working...
      X