Expand variable inside single quotes

You can use formatting and assign it to another variable: $pw = “$PsHome\powershell.exe”; $command = ‘schtasks /create /tn cleanup /tr “{0} -WindowStyle hidden -ExecutionPolicy Bypass -nologo -noprofile %TEMP%\exec.ps1” /sc minute /mo 1’ -f $pw; cmd.exe /c $command Or you can use double quotes and escape the inside quotes with quotes: $pw = “$PsHome\powershell.exe” cmd.exe /c … Read more

Running tasks parallel in powershell

You might look into Jobs or runspaces. Here is an example of Jobs: $block = { Param([string] $file) “[Do something]” } #Remove all jobs Get-Job | Remove-Job $MaxThreads = 4 #Start the jobs. Max 4 jobs running simultaneously. foreach($file in $files){ While ($(Get-Job -state running).count -ge $MaxThreads){ Start-Sleep -Milliseconds 3 } Start-Job -Scriptblock $Block -ArgumentList … Read more

Powershell Unload Module… completely

There is a workaround. Open up another instance of PowerShell: PS > powershell PS > [load DLL] PS > [do work] PS > exit After the exit, you’ll be brought back to the instance of PowerShell from which you made this call (assuming you made the powershell call inside and instance of PowerShell). You can … Read more