I have command that changes the UPN of all mailbox users
Get-ADUser -Filter * -properties homemdb | where {$_.homemdb -ne $null} | ForEach-Object ($_.SamAccountName) {$CompleteUPN = $_.SamAccountName + “@contoso.com”; Set-ADUser -Identity $_.DistinguishedName -UserPrincipalName $CompleteUPN}
The command works using the AD module for powershell. What I would like to do it write a script that does the following.
Runs the command above
Only applies changes to users that need it. (I think this applies the setting to all users with the "homemdb")
I was thinking of setting it as a scheduled task on one of the Domain Controllers. Mypowershell skills are lacking at best, so any guidance on how to set this up would be much appreciated.
Thanks