我正在创建一个SP站点,并且我有一个可选字段“ $ SecondaryAlias”,即使secondaryAlias变量为空,我也希望脚本创建站点,但是却给了我以下错误:
New-SPSite : Cannot bind parameter 'SecondaryOwnerAlias'. Cannot convert value "" to type "Microsoft.SharePoint.PowerShell.SPUserPipeBind". Error: "Value cannot be null.
这是我的secondaryAlias脚本块,我不确定如何正确地对其进行操作:
Do{
$SecondaryAlias = Read-Host 'Optional: SecondaryOwnerAlias'
try {
$user = get-aduser -Filter "samaccountname -eq '$SecondaryAlias' -OR name -eq '$SecondaryAlias'"
}
catch {
"no secondaryOwnerAlias has been chosen"
break
}
Do{
If (!$user) {
"The user does not exist in AD"
break
}
Else {
"The user does exist in AD:`nsamaccountname: $($user.samaccountname)`nFull Name: $($user.name)"
}
}While (($null -eq $SiteOwnerAlias) -or ( "" -eq $SiteOwnerAlias))
}until ($user)
New-SPSite -Url $siteUrl -name $sitename -Language $SiteLanguage -Template $SiteTemplate -OwnerAlias $SiteOwner -SecondaryOwnerAlias $SecondaryAlias
谢谢
答案 0 :(得分:1)
因此,您需要让SecondaryAlies处于另一种if/else
状态,如下所示:
If($SecondaryAlias)
{
New-SPSite -Url $siteUrl -name $sitename -Language $SiteLanguage -Template $SiteTemplate -OwnerAlias $SiteOwner -SecondaryOwnerAlias $SecondaryAlias
}
else
{
New-SPSite -Url $siteUrl -name $sitename -Language $SiteLanguage -Template $SiteTemplate -OwnerAlias $SiteOwner
}
希望它能满足您的需求。
PS:我没有检查其他逻辑;只回答了您的特定逻辑问题。