I guess we all don't remember ; is the simplest way to make a script wait for the previous command, the old DOS ';'. I use this ALLOT to convert long scripts to run in a remote session with enter-pssession, because Microsoft decided to make remote PowerShell session awkwardly restricted.
I've written allot of scripts to run in TaskMgr and that can be quite a process to develop, so I use -command 'command to run;then another;then another', and so on.
I remember the wonderfully useful 'Call' command in DOS batch file scripting, and it looks like what 'wait-process' does, but not quite, as that specifically waits for a denoted process, not for the line above, which is what was originally asked all those years ago (what an old still-open thread!).
So here is a reminder (update) that the newer versions of PowerShell (not PS 1, good God don't use THAT!) has allot of (new) options for stopping inside, not exiting, the console, like 'exit' does, as some thought the original question was (you can simply 'break' to stop at that point...
- Disable-PSBreakpoint Cmdlet Microsoft.PowerShell.U...
Disables the breakpoints in the current console.
- Enable-PSBreakpoint Cmdlet Microsoft.PowerShell.U...
Enables the breakpoints in the current console.
- Get-PSBreakpoint Cmdlet Microsoft.PowerShell.U...
Gets the breakpoints that are set in the current session.
- Remove-PSBreakpoint Cmdlet Microsoft.PowerShell.U...
Deletes breakpoints from the current console.
- Set-PSBreakpoint Cmdlet Microsoft.PowerShell.U...
Sets a breakpoint on a line, command, or variable.
But Break isn't what was asked, right prior answers before mselmany (https://stackoverflow.com/users/15224124/mselmany)?
So the answer to the question How to to use a single script to run and then wait for the next command
is to use
&& or ; or |out-null or even |$null
Note: If you ever need to look something up use get-help, or find-command. That's why you have to regularly update your help files -see command below
#Update-Windows_Powerhell.ps1
$modules = $null
$modules = (Get-Module -ListAvailable).name
foreach ($module in $modules) {
Write-Output $module
Import-Module $module -NoClobber -Verbose -ErrorAction SilentlyContinue;
if((Get-Module -ListAvailable $module).Version -lt (Get-Module $module).Version){
Update-Help -Module $module -Confirm:$false
}
}
**you can change 'listAvailable' to find a speciifc module like '-ListAvailable Graph
For more, that update regularly now, look at my Tech Blog:
Click www.Burwell.tech!