In this post we provide an example of how we can reapply the Cloud Policy for Microsoft 365 using PowerShell.
Sometimes when we make changes to a Microsoft 365 policy, we don’t have time to sit around waiting for the policy to take affect if we’re debugging in situ. And running a device sync doesn’t always work.
The script essentially uses Invoke-Command
to run a piece of code on the remote computer, iterating through every user sid in HKEY_USERS and deleting the CloudPolicy key if it exists.
$computerName = "xxx"
Invoke-Command -ComputerName $computerName -ScriptBlock {
foreach($sid in Get-ChildItem -Path "Registry::HKEY_USERS") {
$keypath = "Registry::$sid\Software\Microsoft\Office\16.0\Common\CloudPolicy"
if (test-path $keypath) {
write-host "Deleting $keypath"
Remove-Item -Path $keypath -Recurse -Force
}
}
}
If the user then closes and re-opens their Microsoft 365 application (Word, Excel, Access etc.), the new policy settings should take effect immediately.