Powershell 提示远程用户输入
Powershell Prompt For Input From Remote User
我想 运行 在远程计算机上执行关机命令,但我希望提示用户接受或拒绝该命令。这就是我所拥有的。它提示本地用户输入 $computername,我需要 运行 远程计算机用户的输入提示,然后执行关机脚本。
$server=read-host 'Enter Name'
$choice = ""
while ($choice -notmatch "[y|n]"){
$choice = read-host "Do you want to continue? (Y/N)"
}
if($choice -eq "y"){
shutdown /m \$server /r /t 00
}
else {write-host "Please contact your systems administrator."}
最大的问题是向用户显示消息,因为它必须在该用户会话中以交互方式运行。
一种方法,如果您只想显示计算机即将关机的消息,而不希望它们能够取消,则可以利用 remote shutdown command:
shutdown -m //computername -r -f -c "MESSAGE" -t 120
如果你需要更全面的关闭,用户可以随时取消(相信我,他们总是会选择取消)关闭,那么你需要使用类似 PsExec 的东西,你 运行 交互式会话中的脚本:
psexec.exe \computername -I message.vbs
其中 message.vbs 可以是您需要 运行 的任何更复杂的脚本(或 PowerShell 脚本)。
我想 运行 在远程计算机上执行关机命令,但我希望提示用户接受或拒绝该命令。这就是我所拥有的。它提示本地用户输入 $computername,我需要 运行 远程计算机用户的输入提示,然后执行关机脚本。
$server=read-host 'Enter Name'
$choice = ""
while ($choice -notmatch "[y|n]"){
$choice = read-host "Do you want to continue? (Y/N)"
}
if($choice -eq "y"){
shutdown /m \$server /r /t 00
}
else {write-host "Please contact your systems administrator."}
最大的问题是向用户显示消息,因为它必须在该用户会话中以交互方式运行。
一种方法,如果您只想显示计算机即将关机的消息,而不希望它们能够取消,则可以利用 remote shutdown command:
shutdown -m //computername -r -f -c "MESSAGE" -t 120
如果你需要更全面的关闭,用户可以随时取消(相信我,他们总是会选择取消)关闭,那么你需要使用类似 PsExec 的东西,你 运行 交互式会话中的脚本:
psexec.exe \computername -I message.vbs
其中 message.vbs 可以是您需要 运行 的任何更复杂的脚本(或 PowerShell 脚本)。