Getting started with PowerShellLoopsOperatorsUsing ShouldProcessPowerShell ClassesSwitch statementWorking with ObjectsUsing existing static classesBasic Set OperationsPowerShell FunctionsSending EmailHandling Secrets and CredentialsPowershell RemotingPowerShell "Streams"; Debug, Verbose, Warning, Error, Output and InformationVariables in PowerShellCommunicating with RESTful APIsWorking with the PowerShell pipelinePowerShell Background JobsReturn behavior in PowerShellWorking with XML FilesIntroduction to PsakeUsing the progress barStringsTCP Communication with PowerShellSharePoint ModuleAliasesAutomatic VariablesEnvironment VariablesPowershell profilesEnforcing script prerequisitesUsing the Help SystemSplattingDesired State ConfigurationSigning ScriptsSecurity and CryptographyCSV parsingIntroduction to PesterModules, Scripts and FunctionsPowerShell.exe Command-LineCommon parametersParameter setsRegular ExpressionsPowerShell Dynamic ParametersWMI and CIMGUI in PowershellConditional logicURL Encode/DecodeMongoDBRunning ExecutablesError handlingHashTablesActiveDirectory modulepowershell sql queriesAutomatic Variables - part 2Package managementCmdlet NamingBuilt-in variablesCreating DSC Class-Based ResourcesPowershell ModulesPowerShell WorkflowsHow to download latest artifact from Artifactory using Powershell script (v2.0 or below)?Calculated PropertiesSpecial OperatorsAnonymize IP (v4 and v6) in text file with PowershellComment-based helpAmazon Web Services (AWS) Simple Storage Service (S3)Amazon Web Services (AWS) RekognitionPSScriptAnalyzer - PowerShell Script AnalyzerNaming ConventionsEmbedding Managed Code (C# | VB)Archive ModuleInfrastructure AutomationScheduled tasks moduleISE module

ActiveDirectory module

Other topics

Remarks:

Please remember that PowerShell's Help System is one of the best resources you can possibly utilize.

Get-Help Get-ADUser -Full
Get-Help Get-ADGroup -Full
Get-Help Get-ADComputer -Full
Get-Help Get-ADObject -Full

All of the help documentation will provide examples, syntax and parameter help.

Module

#Add the ActiveDirectory Module to current PowerShell Session
Import-Module ActiveDirectory 

Users

Retrieve Active Directory User

Get-ADUser -Identity JohnSmith

Retrieve All Properties Associated with User

Get-ADUser -Identity JohnSmith -Properties *

Retrieve Selected Properties for User

Get-ADUser -Identity JohnSmith -Properties * | Select-Object -Property sAMAccountName, Name, Mail

New AD User

New-ADUser -Name "MarySmith" -GivenName "Mary" -Surname "Smith" -DisplayName "MarySmith" -Path "CN=Users,DC=Domain,DC=Local"

Groups

Retrieve Active Directory Group

Get-ADGroup -Identity "My-First-Group" #Ensure if group name has space quotes are used

Retrieve All Properties Associated with Group

Get-ADGroup -Identity "My-First-Group" -Properties *

Retrieve All Members of a Group

Get-ADGroupMember -Identity "My-First-Group" | Select-Object -Property sAMAccountName
Get-ADgroup "MY-First-Group" -Properties Members | Select -ExpandProperty Members

Add AD User to an AD Group

Add-ADGroupMember -Identity "My-First-Group" -Members "JohnSmith"

New AD Group

New-ADGroup -GroupScope Universal -Name "My-Second-Group"

Computers

Retrieve AD Computer

Get-ADComputer -Identity "JohnLaptop"

Retrieve All Properties Associated with Computer

Get-ADComputer -Identity "JohnLaptop" -Properties *

Retrieve Select Properties of Computer

Get-ADComputer -Identity "JohnLaptop" -Properties * | Select-Object -Property Name, Enabled

Objects

Retrieve an Active Directory Object

#Identity can be ObjectGUID, Distinguished Name or many more
Get-ADObject -Identity "ObjectGUID07898" 

Move an Active Directory Object

Move-ADObject -Identity "CN=JohnSmith,OU=Users,DC=Domain,DC=Local" -TargetPath "OU=SuperUser,DC=Domain,DC=Local"

Modify an Active Directory Object

Set-ADObject -Identity "CN=My-First-Group,OU=Groups,DC=Domain,DC=local" -Description "This is My First Object Modification"

Contributors

Topic Id: 8213

Example Ids: 26388,26389,26390,26391,26392

This site is not affiliated with any of the contributors.