Script fails when using [Microsoft.VisualBasic.Interaction]::InputBox on a remote computer


hi all,

i've got simple reboot remote computer script works fine, except when add inputbox user enter reason reboot. script fails. haven't been able find root cause , appreciate in finding it. remote computer, in case, windows 2008r2 server , client workstation initiating remote reboot windows 7 pro computer.

following code , following report.wer error report.

thank you.

import-module activedirectory [system.reflection.assembly]::loadwithpartialname('microsoft.visualbasic') | out-null $dir = split-path $myinvocation.mycommand.definition  # remote computer rebooted $computer = "remotecomputernametoreboot"  # variables inputbox $title = "reboot reason" $msg = "enter reason re-booting remote computer.`nthis mandatory." $defaulttext = "enter reason here"  # local computer - script executed on computer $localcomputer = $env:computername $complocal = get-adcomputer -filter {name -like $localcomputer} -searchbase "dc=no1,dc=no2" -properties "*" $complocaldesc = $complocal.description  # local logged on user - local computer $localusercomputer = get-wmiobject -computername $localcomputer -namespace root\cimv2 -class win32_computersystem -property "*" $localdomainname = $localusercomputer.username $splitlocaldomainname = $localdomainname.split(''\') $localusername = $splitlocaldomainname[1] $localusernameprops = get-aduser -filter {samaccountname -like $localusername} -properties '*' $localuserfullname = $localusernameprops.name  # user executing script $username = $env:username $exeuser = get-aduser -filter {samaccountname -like $username} -properties '*' $userfullname = $exeuser.name  # remote user credentials initiating reboot $servadmin = "$computer\remotecomplocaladmin" $servadminpwd = convertto-securestring -asplaintext 'remotecomplocaladminpassword' -force $servadmincreds = new-object -typename system.management.automation.pscredential -argumentlist $servadmin, $servadminpwd  $rebootreason = [microsoft.visualbasic.interaction]::inputbox($msg, $title, $defaulttext) if ($rebootreason){ 	if ($rebootreason -ne $defaulttext){ 		# reboot command 		(get-wmiobject win32_operatingsystem -computername $computer -credential $atrcreds).win32shutdown(6) | out-null 		 		$dt = get-date -format f 		$smtpserver = "our.emailserver.com" 		$to = "tome@emailserver.com" 		$from = "fromthem@emailserver.com" 		$subject = "remote computer restarted" 		$body += "<b>script executed from:</b> $localcomputer ($complocaldesc) - $dt<br>" 		$body += "<b>script executed on</b>: $computer (bus entrance promo kiosk) - $dt<br>" 		$body += "<b>script local user:</b> $localusername ($localuserfullname)<br>" 		$body += "<b>script executed by:</b> $username ($userfullname)<br>" 		$body += "<b>reboot reason:</b> $rebootreason<br>" 		send-mailmessage -smtpserver $smtpserver -to $to -from $from -subject $subject -body $body -bodyashtml -priority high 	} 	else{ 		. "$dir\restart-remotecomputer_test2.ps1" 		exit 	} } else{ 	break }  $dt = "" $smtpserver = "" $to = "" $from = "" $subject = "" $body = ""

report.wer contents

version=1
eventtype=powershell
eventtime=131344946418003618
reporttype=1
consent=1
uploadtime=131344946418472368
reportidentifier=a7f3d822-0d7b-11e7-b300-002324a67e2d
response.bucketid=3170927621
response.buckettable=29
response.type=4
sig[0].name=nameofexe
sig[0].value=powershell.exe
sig[1].name=fileversionofsystemmanagementautomation
sig[1].value=6.1.7601.23403
sig[2].name=innermostexceptiontype
sig[2].value=system.invalidoperationexception
sig[3].name=outermostexceptiontype
sig[3].value=system.invalidoperationexception
sig[4].name=deepestpowershellframe
sig[4].value=unknown
sig[5].name=deepestframe
sig[5].value=system.windows.forms.form.showdialog
sig[6].name=threadname
sig[6].value=unknown
dynamicsig[1].name=os version
dynamicsig[1].value=6.1.7601.2.1.0.256.48
dynamicsig[2].name=locale id
dynamicsig[2].value=1033
state[0].key=transport.donestage1
state[0].value=1
state[1].key=datarequest
state[1].value=idata=1/ndumpfile=//upload//icab//407-95662298dc93448eb6a06926998b23b9-446faef89b93a95b18350ed6d3238554-5-127724979205-powershell-6-1-7601-2.cab/ndumpserver=watson.microsoft.com/nresponseserver=watson.microsoft.com/nresponseurl=//dw//genericfour.asp?ibucket=127724979205&szcab=95662298dc93448eb6a06926998b23b9.cab&eventtype=powershell&buckethash=446faef89b93a95b18350ed6d3238554&mid=5da527db-c7f7-4043-9350-a1e7695e2a1d/nbucket=-1124039675/nbuckettable=29/nresponse=1/n
friendlyeventname=powershell
consentkey=powershell
appname=powershell
apppath=c:\windows\system32\windowspowershell\v1.0\powershell.exe


onward through fog......





hi,

>>except when add inputbox user enter reason reboot. script fails. 

you testing these 2 lines first on remote machine:

[system.reflection.assembly]::loadwithpartialname('microsoft.visualbasic') | out-null [microsoft.visualbasic.interaction]::inputbox('1','2','3')

it prompts errors.

so, suppose try read-host instead.

best regards,

andy


please remember mark replies answers if help.
if have feedback technet subscriber support, contact tnmff@microsoft.com.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client