S
S
Sergey Pugovkin2019-10-18 13:40:30
PowerShell
Sergey Pugovkin, 2019-10-18 13:40:30

Launching powershell with commands using a shortcut?

With what content should I create a bat file (or something like that) that opens a PowerShell console, changes the current folder, and executes a command there? (git pull origin master)? And leave the console open

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2019-10-18
@BeatHazard

You can create a shortcut, specify the launch of Powershell and the script in it in this way
powershell.exe -NoExit -command "C:\Temp\test.ps1"
in the first line of the script, you can change the current folder to the
set-location "c:\" you need Temp"
Next, the command you need git
pull origin master
at startup, the -NoExit key is specified

S
Sergey Kovalev, 2019-10-18
@Sergey-S-Kovalev

If you need to run some command, then insert the following line into the shortcut:
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -Command "stop-vm -name vm-teamviewer;start-sleep -seconds 10;start- vm -name vm-teamviewer"
If you want the window to remain:
powershell.exe -ExecutionPolicy Bypass -NoExit -Command "stop-vm -name vm-teamviewer;start-sleep -seconds 10;start-vm -name vm-teamviewer"
If you need to execute a script:
powershell -ExecutionPolicy Bypass -file "D:\OneDrive\ScriptingGuy\powershell\create-new-vm-wizard.ps1"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question