$SecPass = convertto-securestring -asplaintext -string "password" -force
$PSCredential = new-object System.Management.Automation.PSCredential -argumentlist "user@something.dk",$SecPass
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $PSCredential -Authentication Basic -AllowRedirection
Set-ExecutionPolicy RemoteSigned
Import-PSSession $Session
$users = Get-Mailbox
foreach ($a in $users) {$a.emailaddresses.Add("$($a.alias)@alias.something.dk")}
$users | %{Set-Mailbox $_.Identity -EmailAddresses $_.EmailAddresses}
I have made something very similiar to the above and it works fine.
But I am unsure of how I should validate it agains if the mailbox already has that alias
Because there is a tendency for it to create additional aliases each time I run the script.
Example: In Live Edu there exists main ID user@something.dk
Aliases:
user@alias.something.dkuser@alias1.something.dkany suggestions?