Using ADUC, it can be quite a hassle to find and/or unlock AD accounts. Powershell solves this by providing some neat commands for a system administrator to use.
To list all locked out AD accounts:
Search-ADAccount -LockedOut
To get more info about these accounts, you can do a Full-List:
Search-ADAccount -LockedOut | FL
Furthermore, you can pipe the output to quickly unlock some/all AD accounts:
Search-ADAccount -LockedOut | Unlock-ADAccount
You can quickly check which mailbox has e-mail forwarding settings enabled through the EMS:
Get-Mailbox -Filter {ForwardingAddress -ne $null} | FT Name,ForwardingAddress,DeliverToMailboxAndForward -Autosize
You can use the cmdlet above and process its output or export it to a CSV (using Export-CSV).
Sometimes you may want to set or clear attributes of an AD object (e.g. the extensionAttributes of an AD user) through Powershell.
To set an attribute:
Set-ADUser -Identity "AnyADUser" -Add @{extensionAttribute15="SomeValue"}
To clear an attribute (i.e. unset the attribute):
Set-ADUser -Identity "AnyADUser" -Clear extensionAttribute15
The Office365 Admin portal clearly shows which users are synced to AD and which are cloud only. In Powershell, this is less clear. To find out which are cloud-only, you need to check the value of LastDirSyncTime. If it is empty, then the user was never synced from AD, and thus, is a cloud-only user.
Log on to your Office 365 tenant through Powershell, then run:
Get cloud-only users:
Get-MsolUser -All | Where { $_.LastDirSyncTime -eq $null }
Get synchronized-only users:
Get-MsolUser -All | Where { $_.LastDirSyncTime -ne $null }
This one-liner will output a list of installed programs, similar to what you get when looking it up through Control Panel → Add/Remove Programs.
Get-WmiObject -Class Win32_Product | Select-Object -Property Name
The advantage of this cmdlet is that you can dump it to a text file:
Get-WmiObject -Class Win32_Product | Select-Object -Property Name > Software.txt
And through PS remoting, you can also run this on remote systems.
You can easily perform 'diff' style text comparisons with Powershell:
Compare-Object -ReferenceObject (Get-Content file1.txt) -DifferenceObject (Get-Content file2.txt)
You can redirect the output of a Powershell script to a file. This is called transcribing, and is very useful if you have some Powershell scripts as scheduled tasks and wish to log its output.
$ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" Start-Transcript -Path "C:\transcript.log" -Append # # My script code goes here... # Stop-Transcript
You can mail-enable multiple accounts with a single Powershell command. Look below for some examples:
Mail-enable AD accounts whose first name is John:
Get-ADUser -Filter * | Where {$_.GivenName -like "John"} | ForEach-Object { Enable-Mailbox -Identity $_.DistinguishedName }
Mail-enable all accounts in an OU called Engineering:
Get-ADUser -Filter * -SearchBase "OU=Engineering,DC=contoso,DC=local" | ForEach-Object { Enable-Mailbox -Identity $_.DistinguishedName }
Easily count the number of mailboxes located on an Exchange (mailbox) server with Powershell:
[PS] >Get-Mailbox | Group-Object -Property:ServerName | Select-Object Name,Count Name Count ---- ----- exchange01 43 exchange02 100 exchange03 252
« ‹ | October 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |