Powershell New Mailbox命令不接受-Equipment参数
我正在尝试通过脚本在Exchange Online中创建新资源,如果我手动键入该行,它会工作,但当我运行脚本时,命令new Mailbox突然无法接受“-Equipment”参数 脚本在以下行失败:Powershell New Mailbox命令不接受-Equipment参数,powershell,office365,exchange-server,Powershell,Office365,Exchange Server,我正在尝试通过脚本在Exchange Online中创建新资源,如果我手动键入该行,它会工作,但当我运行脚本时,命令new Mailbox突然无法接受“-Equipment”参数 脚本在以下行失败: New-Mailbox -Name "$($Resource)" -$($Type) 错误显示如下: A positional parameter cannot be found that accepts argument '-Equipment'. + CategoryInfo
New-Mailbox -Name "$($Resource)" -$($Type)
错误显示如下:
A positional parameter cannot be found that accepts argument '-Equipment'.
+ CategoryInfo : InvalidArgument: (:) [New-Mailbox], ParameterBindingException"
PowerShell将
-$($Type)
解释为字符串参数,而不是参数名。用于有条件地传递参数,如下所示:
$extraParams = @{ $Type = $true }
New-Mailbox -Name "$($Resource)" @extraParams
我不确定Exchange Online中还有哪些其他类型的邮箱可用,但您可能需要了解这一点并应用一些输入验证:
param(
[string]$Resource,
[ValidateSet('Equipment','Person','Room')]
[string]$Type
)
# do other stuff here
# If someone passed a wrong kind of `$Type`, the script would have already thrown an error
$extraParams = @{ $Type = $true }
New-Mailbox -Name "$($Resource)" @extraParams
PowerShell将
-$($Type)
解释为字符串参数,而不是参数名。用于有条件地传递参数,如下所示:
$extraParams = @{ $Type = $true }
New-Mailbox -Name "$($Resource)" @extraParams
我不确定Exchange Online中还有哪些其他类型的邮箱可用,但您可能需要了解这一点并应用一些输入验证:
param(
[string]$Resource,
[ValidateSet('Equipment','Person','Room')]
[string]$Type
)
# do other stuff here
# If someone passed a wrong kind of `$Type`, the script would have already thrown an error
$extraParams = @{ $Type = $true }
New-Mailbox -Name "$($Resource)" @extraParams