Powershell v4 script doesn't fire as exe (via PS2EXE) to reset sessions -
i'm trying write simple script allow staff reset citrix sessions on machines not local admins. following works .ps1. doesn't reset session when converted .exe ps2exe, , run.
the thought behind using .exe can obscure password service account needs run command under (it's local admin on citrix servers). yes, i'm aware of risk, , .ps1 can reasonably extracted .exe. i'm sure can in gp, i'd approach.
so, why wouldn't below reset session when run .exe? (i've tried hard-coding in values server , session, think might credential issue, not variable or scriptblock issue.)
$strscriptuser = "domain/svcacct" $strpass = "password" $pss = convertto-securestring $strpass -asplaintext -force $cred = new-object system.management.automation.pscredential $strscriptuser,$pss $server = read-host 'which citrix server?' $sid = read-host 'what session number reset? (be careful!)' start-job -scriptblock { reset session $using:sid /server $using:server > /temp2/result.txt } -credential $cred
thanks comments original question, able working. think issue was exiting prematurely, before reset had time complete. using start-job
, wait-job
seems resovle this.
here's final working version. added in session listing , navigation.i'm sure there more elegant ways, works on end. let me know if sins egregious overlook.
$strpass = "password" $pss = convertto-securestring $strpass -asplaintext -force $credential = new-object -typename system.management.automation.pscredential ` -argumentlist "domain\svcacct",$pss $sid=0 write-host "***session destroyer(!) v1***" while ($sid -eq "0" -or $sid -eq "n" -or $sid -eq "n") { $server = read-host 'which citrix server? (or q quit)' if ($server -eq "q" -or $server -eq "q") {exit} query session /server $server $sid = read-host 'what session number reset? careful! ` (or q quits, n new server)' if ($sid -eq "q" -or $sid -eq "q") {exit} } $job = start-job -credential $credential –scriptblock { reset session $using:sid /server $using:server } wait-job $job write-host "done. check below make sure." query session /server $server pause
Comments
Post a Comment