Powershell Cheat Sheet

How to find the command you are interested

Get-Command | Where-Object {$_.CommandType -eq ‘cmdlet’}

Get-Command | Where-Object {$_.Name -like ‘*clear*’}

Get-WindowsFeature *dns*

Get-Help *-DNS*

Some useful commands for managing AD objects.

get-aduser -filter * -properties lastlogondate | ft name, lastlogondate

get-aduser -filter * -properties lastlogondate,passwordlastset | ft name, lastlogondate,passwordlastset

get-aduser -filter { enabled -ne $true }

Search-ADAccount -AccountDisabled ( help Search-ADAccount for more syntax )

Search-ADAccount -AccountDisabled -usersonly | fl name

Search-ADAccount -Lockedout

get-ADOrganizationalUnit -filter * | fl Name

New-ADOrganizationalUnit “Test OU”
New-ADGroup -Name “IT Department” -GroupScope Global -path “ou=Test OU,dc=econe.dc=pri”

Add-ADGroupMember “IT Department” helpdesk

Get-ADGroupMember “Domain Admins” | ft name

Get-ADPrincipalGroupMembership helpdesk | ft name

Get-AdGroup “IT Department”


Bulk activities

csvde -f output1.csv -d “cn=users,dc=econe,dc=pri” -r “objectclass=user”

similar command is – “ldifde” ( the output will be in ldf ¬†format )

Import-csv newusers.csv | New-AddUser ( this way will provide a way to user bulk creation, the newusers.csv file needs to be constructed properly )