表单从包含多个变量的消息框中获取结果确定并取消

时间:2016-01-07 19:24:56

标签: powershell dialog

我正在尝试从我编写的脚本中获取OK或Cancel结果,我涉及多个变量,可以深入研究一条消息。附件是我的剧本,基本上我需要做的就是" OK"继续按下A​​D帐户创建,当"取消"是关闭表格还是回到它我还没有决定,我认为我在正确的轨道上将其指定为变量但是当选择确定或取消时创建帐户。顺便说一下,我的代码在附图中。

Script

1 个答案:

答案 0 :(得分:0)

查找Switch命令。以下是我在你的情况下如何使用它:

Switch($true){
    {$RadioButton1.Checked} { $Room = 'Yellowstone Room #6042' }
    {$RadioButton1.Checked} { $Room = 'Shenandoah Room #6043' }
    {$RadioButton1.Checked} { $Room = 'Everglades Room #6042' }
    {$RadioButton1.Checked} { $Room = 'Gettysburg Room #6038' }
    {$RadioButton1.Checked} { $Room = 'Antietam Room #6030' }
    {$RadioButton1.Checked} { $Room = 'Yosemite Room #6039' }
    {$RadioButton1.Checked} { $Room = 'Zion Room #6040' }
    default { $Room = $Null }
}

$MsgBox = [System.Windows.Forms.MessageBox]::Show("Thank you $a, you have selected $Room and breakout $h, please contact Patrick Sullivan (703-434-4621) for technical assistance or the NSS servicedesk (1-800-871-9983)","Thank you for registering!",1)
If($MsgBox -eq 'OK'){
    New-ADUser -Name $d -AccountExpirationDate $j -AccountPassword $k -Description $i -DisplayName $d.prop -Enabled $true -GivenName $a -MobilePhone $e -SamAccountName $c -Surname $b -Path "OU=VPC VDI,OU=VPC,OU=Hosted Accounts,DC=net,DC=its,DC=l-3com,DC=com"
}
Else{
    Write-Host "You pressed cancel"
}

那应该做你正在尝试的事情。或者,不需要更改代码......

"OK"部分更改为If($1 -eq "OK"){New-ADUser .....}Else{Write-Host "You pressed cancel!"}