active directory

Powershell Tuesday Quick Tip #5

Here’s another one from the easy but annoying to rethink stack.
People, as someone once said, are ‘squishy and move around a lot’. Not only do they move but they change and sometimes the change involves their names.
For example, the customer service person gets married or the sales manager gets divorced.(Hopefully not for the same reason – but that’s a different blog)

So you can either fire up the Active Directory tool of your choice (ADAC or ADUC) OR switch over to your PowerShell console that you have open already.
… you DO have it open already right?

Set-AdUser -Identity Leia -Surname 'Solo' -DisplayName "Leia Solo"
Set-Mailbox -Identity Leia -PrimarySmtpAddress 'LeiaSolo@NewRepublic.gov' -EmailAddressPolicyEnabled:$False -DisplayName 'Leia Solo' -EmailAddresses @{add ='LeiaOrgana@NewRepublic.gov'}

The first line “Set-ADUser” changes Leia’s surname to Solo and corrects her display name. The second line, “Set-Mailbox” changes her primary email address to “LeiaSolo@NewRepublic.gov” along with her display name while adding her original email address back in as an alternate. This is so Leia will continue to get email from some people that haven’t gotten the happy news yet.

These two lines require that you have the Active Directory module and a remote session to either Office365 or your Exchange server.

Next week I’ll be blogging from the PowerShell + DevOps Global Summit in beautiful Bellevue WA!

 

Powershell Tuesday Quick Tip #2

This week is an easy one. Cleaning up Active Directory of old computers. Sometimes a machine gets retired or just completely craters and in the haste to get the user back up and going…. some clean up is forgotten. Easy to fix. this little snippet returns the time since PC has logged into the domain in DDD.HH:MM:SS format

$timespan = '90.00:00:00'
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan $timespan|
Foreach-Object {Write-output $_.name} 

Of course it’s easy to add

 |Export-csv -Path C:\OLDPC.csv 

to the pipeline which gives you a CSV file to review and feed into a “Delete-OldComputer” oneliner!

See ya next week!