Hello!! Sorry, but I believe I had previously posted in the wrong section of the forum. My mistake.....
Well here's to hoping this is the correct forum area this time around.
I'm trying to create a powershell script that can add an email address to all users based on their first initial and last names.
Example:
User has a name of Adam Smith. His current email is adam.smith@domain.com
I wish to create another email as "asmith@domain.com"
My issue is that I believe that the get-user cmdlet is the only one that will have the first name and last name properties and NOT get-mailbox. Something like this currently gets me exactly what I need in terms of initial+lastname.
get-user | Select firstname, lastname,@{Name="FirstInitial+LastName";Expression={$_.FirstName[0] + $_.LastName}}
I also am able to add a new email address based on an alias. My question is how can I somewhat combine these two so that I can add that "asmith@domain.com" email to users? This is what I found/have so far. I believe it will work but only based on the alias and not what I need.
$Mailboxes = Get-Mailbox Foreach ($Mailbox in $Mailboxes) { $NewAddress = $Mailbox.Alias + "@domain.com " $Mailbox.EmailAddresses += $NewAddress Set-Mailbox -Identity $Mailbox.Alias -EmailAddresses $Mailbox.EmailAddresses }
Currently, my only workaround is to use a CSV with the alias and new address I require. This method works but is still somewhat tedious. Any help would be appreciated!
This is what I'm using with the CSV method (again, not preferable)
Import-Csv C:\users.csv | Foreach{set-mailbox $_.Alias -EmailAddresses @{add=$_.emailaddress}}
Thanks!