PowerShell Active Directory Commands

PowerShell Active Directory Commands

PowerShell Active Directory Commands

Import-Module ActiveDirectory

Set-Location AD:

Get-ChildItem

Set-Location “dc=rickyadams,dc=com”

Set-Location “OU=TestOU”

Set-ItemProperty -Path ‘.\CN=Ricky Adams’ -Name “Description” -Value “Virtualization Cloud God”

Get-ADObject -LDAPFilter “(&(operatingSystem=Windows Server 2008 R2 Standard) (objectClass=computer))” -SearchBase “dc=rickyadams,dc=com” -SearchScope Subtree

Search-ADAccount -PasswordExpired -UsersOnly -SearchBase “OU=TestOU,dc=rickyadams,dc=com” -SearchScope OneLevel

 

List All Servers in AD

Get-ADComputer-Filter {OperatingSystem -Like”Windows Server*”} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap-Auto

# Only disabled computer accounts
Get-QADComputer-ldapFilter‘(userAccountControl:1.2.840.113556.1.4.803:=2)’# Only enabled computer accountsGet-QADComputer-ldapFilter‘(!(userAccountControl:1.2.840.113556.1.4.803:=2))’

#List Active Servers
Get-ADComputer-LDAPFilter“((objectcategory=computer)(&(operatingsystem=*Server*))(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))))” -Property *-SearchBase“OU=Servers,DC=rickyadams,DC=com”| Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap-Auto

 

 

 

Moves

Move-ADObject ‘CN=myservername,OU=Production,OU=Region1,OU=Servers,DC=rickyadams,DC=com’ -TargetPath ‘OU=NewRegion,OU=FieldOffices,OU=Server Infrastructure,DC=rickyadams,DC=com’

 

GPO

Invoke-GPUpdate -Computer theservername -Force

Comments are closed.