办公室365在线同步,找不到用户
问题描述:
我很新的PowerShell(2个月的经验),我创建自己的脚本来自动执行一些任务。办公室365在线同步,找不到用户
现在我工作的一个usercreation脚本。一切工作正常,直到我到达office365部分。
<Creating AD user based on template and filled info>
<Creating Exchange emailbox>
...
#Retrieving email to specify user
$email = (Get-ADUser $initials -Properties mail).mail
#Remoting into server that has Azure AD Sync installed and forcing sync
Invoke-Command -ComputerName <servername> -ScriptBlock {Start-ADSyncSyncCycle -PolicyType Delta} -Credential $AdminCredentials
#Waiting until sync is done, 30 seconds for testing purposes, can be lowered after some testing
Write-host "Waiting untill sync is done"
Start-Sleep -s 30
#Connecting to office365
Connect-MsolService -Credential $OfficeCredentials
#Creating Licence withouth exchange
$NoExchange = New-MsolLicenseOptions -AccountSkuId syndication-account:O365_BUSINESS_PREMIUM -DisabledPlans "EXCHANGE_S_STANDARD"
#applying licence to user
Set-MsolUserLicense -UserPrincipalName $email -LicenseOptions $NoExchange
现在,这最后一部分是我得到以下错误:
Set-MsolUserLicense : User Not Found. User: .
At <path>\UserCreation.ps1:145 char:1
+ Set-MsolUserLicense -UserPrincipalName $email -LicenseOptions $NoExchange
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUserLicense], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Administration.Automation.SetUserLicense
意味着用户在Office 365不存在甚至寿我强迫同步,并出具了等待30秒(刚需确保其同步增长)
如果我试图找到用户脚本返回这个错误,我可以找到它后...
Get-MsolUser -UserPrincipalName $email
我试过把等待时间增加到60秒,但这似乎没有任何差别。 我是否需要“重新启动”脚本或其他东西才能找到用户,或者是否有其他方式可以解决这个问题?
在此先感谢!
答
不,你没有重新启动脚本或做任何花哨可言,只是增加了Sleep
间隔或检查Start-ADSyncSyncCycle
有-Wait
参数(它不应该),或尝试写这样的:
While ((Get-ADSyncConnectorRunStatus).Runstate -eq "Busy") {
Start-Sleep 10
}
因此,事实上,权当我的剧本给了这个错误我去查了查,并且用户在office365 avaible是纯粹的巧合? (发生3次) – FroggyFreshh
因此,如果您能够找到它,如果再次运行该命令会发生什么情况?它工作吗?你有没有尝试设置'睡眠'2-3-5分钟,看看是怎么回事? – 4c74356b41
在尝试此操作时,我刚刚发现了有关我的许可选项中的错误,我会先尝试修复该问题,然后再回到此问题:) – FroggyFreshh