I am trying to load a variable into get-aduser -filter $variable.Property but I can't seem to get it to work.
Here is the code I am working on. This is only one piece of what I am trying to do.
$DisabledMailboxes = get-mailbox | ?{$_.RecipientTypeDetails -eq 'usermailbox' -and $_.AccountDisabled -eq $true} | select UserPrincipalName,PrimarySmtpAddress,RecipientTypeDetails
Foreach ($mb in $DisabledMailboxes) {
$users = Get-aduser -Filter "EmailAddress -eq '$mb.PrimarySmtpAddress'" | select Name,SamAccountName,UserPrincipalName
}
here is what I am trying to accomplish
- Insert all disabled mailboxes in O365 into variable.
- Find the Local AD user account based on the email address from disabledmailboxes variable.
- find out if user is a member of a specific group.
- finally if user is a member of specific group remove from said group and add them to a different group.
The get-aduser -filter yada yada.. is only used so I can get the SamAccountName and then in turn use get-AdPrincipalGroupMembership.
Any help would be greatly appreciated.
Thanks-