0
我很新的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秒,但這似乎沒有任何差別。 我是否需要「重新啓動」腳本或其他東西才能找到用戶,或者是否有其他方式可以解決這個問題?
在此先感謝!
因此,事實上,權當我的劇本給了這個錯誤我去查了查,並且用戶在office365 avaible是純粹的巧合? (發生3次) – FroggyFreshh
因此,如果您能夠找到它,如果再次運行該命令會發生什麼情況?它工作嗎?你有沒有嘗試設置'睡眠'2-3-5分鐘,看看是怎麼回事? – 4c74356b41
在嘗試此操作時,我剛剛發現了有關我的許可選項中的錯誤,我會先嚐試修復該問題,然後再回到此問題:) – FroggyFreshh