Forum Discussion
Jesper Stein
Jan 18, 2018Brass Contributor
Find user without mailbox
Hi. Im trying to create a script that loads users from an AD Group and filter them based on an attribute. My goal is to have a script that loads users from a group, finde the ones that do not have a ...
- Jan 18, 2018
I dont have access to AD right now, but i think you could do something like this. ! in front of $user.msExchMailboxGuid means that if the variable is null(empty), it should create a mailbox, if its already have a mailbox, a message stating this is dispalyed. Hope this works, or sett you on the right track.
$Users = Get-ADGroupMember -Identity "S_Enable_Exch2010User" | Get-ADUser -filter {msExchMailboxGuid -like "*"} foreach ($user in $users) { if(!$user.msExchMailboxGuid) { enable mailbox command } else { $user.firstname+"already have a email account." } }
Pablo R. Ortiz
Jan 31, 2018Iron Contributor
Yes, if you don't pipe $_ in ForEach statement then you will get All Users. Try this instead (replace 'mydomain.com' with your desired domain, and samaccountname with the property you want):
$Users = Get-ADGroupMember -Identity "S_Enable_Exch2010User"
ForEach ($User in $Users) {
If !($_.msExchMailboxGuid) {
Set-ADUser -Identity $User -EmailAddress ($_.samaccountname + '@mydomain.com')
}