I have a strange issue on a Windows Server 2012 R2 here that just does not make any sense to me at all.
I've got a PowerShell script that basically has the following structure:
Function Something-Different
{
[...]
}
Function Start-Some-Batch
{
Start-Process "K:\Path\To\Batch.cmd"
}
Function Something-Else
{
[...]
}
Something-Different
Start-Some-Batch
Something-Else
However the batch file K:\Path\To\Batch.cmd
never ever gets executed!
Some more information and facts:
- All actions are performed with the same domain user
- PowerShell version is 4.0
- The batch file can be executed without any issues when double-clicking it within Windows Explorer
- The PowerShell script does not provide any error output
- Executing
Start-Process "K:\Path\To\Batch.cmd"
directly from a PowerShell console does also not provide any output nor does it kick of the batch script $error[0]
is empty after the execution- The function
Something-Else
is executing just fine (which meansStart-Some-Batch
is not preventing the PS-script from finishing its execution) - Running the PowerShell script elevated does not change a thing
- Calling the batch script from a cmd.exe prompt does also not start it (elevated or not)
- I am suspecting any of the hundred
Security Settings
that come via group-policy
What could cause such a strange behaviour? I am running out of ideas here.
Here is what works for me, using Powershell v4.
PS C:\Scripts> Start-Process cmd -ArgumentList "/c 1.cmd" -WorkingDirectory c:\test4
Where
1.cmd
lives inc:\test4
The best workaround I've found for this issue comes from an example by Chocolatey for their
Start-ChocolateyProcessAsAdmin
method.Note it can be single or double quotes inside the
-ArgumentList
, they just need escaped when inside other quotes.This works because the first "pass" where PowerShell evaluates the Start-Process line will resolve the $batFile to it's correct value, it then passes the
/c 'C:\Path with Spaces\myfile.bat'
to thecmd.exe
.