You have clarified the logic.
What you need to do is to poll all users and check the two properties of Office
and State
.
A simple sample for your reference:
$users = Get-MsolUser
foreach($user in $users){
if ($user.Office -ne $null -and $user.Office -ne $user.State) {
Set-MsolUser -UserPrincipalName $user.UserPrincipalName -State $user.Office
}
if ($user.Office -eq $null -and $user.State -ne $null){
Set-MsolUser -UserPrincipalName $user.UserPrincipalName -State "$null"
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…