Simple powershell command to execute

Hi,
so I have a very simple power shell command that i want to run automaticly. It works great when doing it in a .bat file, but i would really like to have it under PowerShell

So basicly, what i do without a script to make it work is;

  • going in the folder where i want to run the powershell
  • right click and open powershell
  • type in powershell: python manager.py start
  • type in powershell: python manager.py view

And that’s it!

$path = Get-item -Path C:\Users\Chia\Desktop\Swar
Start-Sleep -Seconds 20
&$path python manager.py start
&$path python manager.py view

Thanks for your help :slight_smile:

MussonKing,
Welcome to the forum.

Even whem I’m a big fan of PowerShell … you know you can even run CMD with a BAT file from PowerShell, don’t you? :wink:

Regardless of that: When you post code or error messages or console output or sample data, please format it as code using the “preformatted text” button ( </> ).
Thanks in advance.

If you have a given path you can save it to a variable with a simple assignment. You don’t need Get-Item in this case.

$path = 'C:\Users\Chia\Desktop\Swar'

Whatfor do you use Start-Sleep? I think you don’t need this.

To combine two elements of a path to a comlete path to be able to use it for a call you can use Join-Path. This way you don’t even need to take care about the backslashes.

It could look like this:

$PythonExecutable = Join-Path -Path $Path -ChildPath 'python.exe'

In your case I’d simply change the current working directory to the desired path. You can use either Set-Location or Push-Location. Push-Location has the advantage that you can come back to the former working directory by calling Pop-Location.

You should always read the complete help for the cmdlets you’re about to use including the examples to learn how to use them.