PowerShell select 三个选项之一
PowerShell select one of three options
目前我有一个 "script" 用户在其中输入用户名,脚本然后在用户交换帐户上设置特定的外出消息 1 个月。
我想添加一项功能,用户可以通过启动标志或弹出菜单从三个不同的选项(办公室 A、办公室 B 和办公室 C)中进行选择。根据他们选择的消息,不同的消息被设置为不在办公室。
#### Connect to exchange ####
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://sto-ms-03/PowerShell -Credential $UserCredential
Import-PSSession $Session
#### User Info ###
$Username = Read-Host -Prompt 'Input your username'
$StartDate = Get-Date (Get-Date).AddDays(-2) -f yyyy/MM/dd
$EndDate = Get-Date (Get-Date).AddMonths(+1) -f yyyy/MM/dd
$Dummymessage1 = "This is dummy number 1"
Set-MailboxAutoReplyConfiguration -Identity "DOMAIN$Username" -StartTime "$StartDate" -EndTime "$EndDate" -ExternalMessage "$Dummymessage1" -InternalMessage "$Dummymessage1"
因此,如果可能的话,我想添加一个弹出按钮,允许选择 A、B 或 C。A、B 和 C 将绑定到 3 个不同的变量,这些变量仅替换 $Dummymessage
编辑:最终使用以下解决方案:
Param
(
[Parameter(Mandatory=$true)]
[ValidateSet("A", "B", "C")]
[string]$Office
)
if($Office -eq 'A') {$Message = "Dummy 1"}
if($Office -eq 'B') {$Message = "Dummy 2"}
if($Office -eq 'C') {$Message = "Dummy 3"}
很有魅力。
我会在脚本的第一行添加一个 Param
部分:
Param
(
[Parameter(Mandatory=$true)]
[ValidateSet("Office A", "Office B", "Office C")]
[string]$Office
)
调用您的脚本的用户现在必须通过 Office A
、Office B
或 Office C
并在控制台中进行选择:
我还允许用户将凭据和用户名传递给脚本(只需将其添加到 Param
块)。
目前我有一个 "script" 用户在其中输入用户名,脚本然后在用户交换帐户上设置特定的外出消息 1 个月。
我想添加一项功能,用户可以通过启动标志或弹出菜单从三个不同的选项(办公室 A、办公室 B 和办公室 C)中进行选择。根据他们选择的消息,不同的消息被设置为不在办公室。
#### Connect to exchange ####
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://sto-ms-03/PowerShell -Credential $UserCredential
Import-PSSession $Session
#### User Info ###
$Username = Read-Host -Prompt 'Input your username'
$StartDate = Get-Date (Get-Date).AddDays(-2) -f yyyy/MM/dd
$EndDate = Get-Date (Get-Date).AddMonths(+1) -f yyyy/MM/dd
$Dummymessage1 = "This is dummy number 1"
Set-MailboxAutoReplyConfiguration -Identity "DOMAIN$Username" -StartTime "$StartDate" -EndTime "$EndDate" -ExternalMessage "$Dummymessage1" -InternalMessage "$Dummymessage1"
因此,如果可能的话,我想添加一个弹出按钮,允许选择 A、B 或 C。A、B 和 C 将绑定到 3 个不同的变量,这些变量仅替换 $Dummymessage
编辑:最终使用以下解决方案:
Param
(
[Parameter(Mandatory=$true)]
[ValidateSet("A", "B", "C")]
[string]$Office
)
if($Office -eq 'A') {$Message = "Dummy 1"}
if($Office -eq 'B') {$Message = "Dummy 2"}
if($Office -eq 'C') {$Message = "Dummy 3"}
很有魅力。
我会在脚本的第一行添加一个 Param
部分:
Param
(
[Parameter(Mandatory=$true)]
[ValidateSet("Office A", "Office B", "Office C")]
[string]$Office
)
调用您的脚本的用户现在必须通过 Office A
、Office B
或 Office C
并在控制台中进行选择:
我还允许用户将凭据和用户名传递给脚本(只需将其添加到 Param
块)。