I am trying to automate the process for a returning user from extended leave
Here is what i want to happen in this script
1 input the returning users
2 search AD to find user
3 (A) if they are gone more then 30 days their mailboxes are archived I need to filter out those users so that I can run a mailbox restore script and then enable user and move to proper OU
3(B) if less then 30 then enable and move the user to their proper OU
The issue I have is Part 3(A) i can manage the rest.
how to get the username from the output of this
Get-ADUser -Filter {Enabled -eq $False} -Properties name,sAMAccountName,lastLogonDate | Where-Object {$_.lastLogonDate -le [DateTime]::Now.AddDays(-30)} | Select name,sAMAccountName,lastLogonDate | Sort-Object name
so the I can use the samacct to find the old archive mailbox and copy into the new mailbox that we created when we re-enable the user The process for the mailbox part to the I have a script for see below
####Restore a Mailbox of returning user###
NOTE: I did this method because Creating/enabling the account and assigning a license creates a new mailbox. I restored to this new mailbox
- Find the inactive Mailbox using link below (most recent date) and copy GUID.
Login details hidden
- Set the values of DELETED Mailbox user you want to restore into Variable $InactiveMailbox ####
$InactiveMailbox = Get-Mailbox -InactiveMailboxOnly -Identity PASTEINACTIVEGUIDHERE
- Find ExchangeGuid of existing mailbox by using command
Get-Mailbox -Identity “NEWLICENSEDRETURNINGUSERADDRESS@facsniagara.on.ca” | Format-List
####Partial Output:
####CalendarRepairDisabled : False
####ExchangeGuid : 44e0511b-e5a8-4d9a-989f-9e1d4812f1c1 < Copy this value from results
####MailboxContainerGuid :
- Restore the Deleted mailbox to the new empty mailbox
New-MailboxRestoreRequest -SourceMailbox $InactiveMailbox.DistinguishedName -TargetMailbox PASTECOPIEDGUIDOFRETURNINGUSER -AllowLegacyDNMismatch
- If impatient: Check status of restore request
Get-MailboxRestoreRequest
Any help that I can get would be greatly appreciated
Thanks