PowerShell Impersonate in WorkFlow for Cim commands -


when running windows powershell workflow nice if possible impersonate user , set new-cimsession connection old servers (without powershell) using dcom or new servers using wsman. there online information available topic.

it's difficult start troubleshooting set-psbreakpoint can't access flow going on in part inlinescript annoying.

however, every time i'm trying run following test-stuff workflow fails pop-up error windows powershell has stopped working. in console says:

microsoft.powershell.utility\write-error : background process reported error following message: . @ test-stuff:59 char:59 

the code:

workflow test-stuff {    param(         [string[]]$servers,         [pscredential]$credentials     )      foreach -parallel ($s in $servers) {         inlinescript {             $sessionparams = @{                 erroraction  = 'stop'                 credential   = $using:credentials                 computername = $using:s             }             try {                 $session = new-cimsession @sessionparams             }             catch {                 $opt = new-cimsessionoption -protocol dcom                 $session = new-cimsession @sessionparams -sessionoption $opt             }              $params = @{                 classname    = 'win32_printer'                 property     = '*'                 cimsession   = $session                 erroraction  = 'stop'             }               if ($printers = get-ciminstance @params) {                 $printers                 remove-cimsession $session             }         }     } } 

when running same code normal function, works fine..


Comments