Windows Powershell方法(对象能做什么)

2019-09-30 14:39:54于海丽


$SwitchUser = ([System.Management.Automation.Host.ChoiceDescription]"&Switchuser")
$LoginOff = ([System.Management.Automation.Host.ChoiceDescription]"&LoginOff")
$Lock= ([System.Management.Automation.Host.ChoiceDescription]"&Lock")
$Reboot= ([System.Management.Automation.Host.ChoiceDescription]"&Reboot")
$Sleep= ([System.Management.Automation.Host.ChoiceDescription]"&Sleep")

$selection = [System.Management.Automation.Host.ChoiceDescription[]]($SwitchUser,$LoginOff,$Lock,$Reboot,$Sleep)
$answer=$Host.UI.PromptForChoice('接下来做什么事呢?','请选择:',$selection,1)
"您选择的是:"
switch($answer)
{
0 {"切换用户"}
1 {"注销"}
2 {"锁定"}
3 {"重启"}
4 {"休眠"}
}


PS C:PowerShell> .test.ps1
接下来做什么事呢?
请选择:
[S] Switchuser  [L] LoginOff  [L] Lock  [R] Reboot  [S] Sleep  [?] 帮助 (默认值为“L”): Reboot
您选择的是:
重启