c# - Script stops on specific command without go into catch block -


i have powershell script powercli commands install , configure virtual machines.

these settings in environment

  • windows server 2008 r2
  • esx 4.1
  • powershell v2
  • powercli 5.1

the script triggered user on website. following code start script. pathtoscript unc path

const string path32bitpowershell = @"c:\windows\syswow64\windowspowershell\v1.0\powershell.exe";  public static void run32bitpowershell(string pathtoscript, boolean waitforexit, string arguments = "") {     process powershellprocess = new process();     powershellprocess.startinfo.createnowindow = true;     powershellprocess.startinfo.windowstyle = processwindowstyle.normal;     powershellprocess.startinfo.filename = path32bitpowershell;     powershellprocess.startinfo.workingdirectory = @"c:\";     powershellprocess.startinfo.arguments = pathtoscript + " " + arguments;      powershellprocess.start();      if (waitforexit)     {         powershellprocess.waitforexit();     } } 

the script has 2 global settings:

$erroractionpreference = "stop" $confirmpreference = "none" 

the whole code inside try block catch/finally code never goes catch block. know because wrote 1 time first line in catch block stop-computer -force -confirm:$false , webserver still running after 5 minutes after script finished.

the code stops on command invoke-vmscript:

invoke-vmscript -vm $vm -scripttype bat -scripttext "powershell.exe  -executionpolicy bypass -nologo -noninteractive -noprofile -command set-executionpolicy unrestricted -scope currentuser" -guestuser "***" -guestpassword "****"   

the exit code c# process 1

important:

the script runs perfectly, wenn start interactive (from ise) ! issue occurs when webserver starts (non-interactive).

someone has idea, problem ?

/update

it works directly powershell command line, interactive

maybe try

$global:erroractionpreference = 'stop'

$global:confirmpreference = 'none'

worked me when had similar problem.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -