Powershell – Batch script is not getting executed when called by Start-Process Cmdlet

batch-filepowershellwindows-server-2012-r2

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 means Start-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.

Best Answer

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 in c:\test4