Table of Contents
Description
Here are some great commands for AD enumeration using the Active-Directory module in Powershell. It is often pre-installed on domain joined hosts but we can download it from here. Of course we could use PowerView as well or BloodHound but this is more LOL approach.
Download
To download the ActiveDirectory module we will have to download RSAT (Remote System Administration Tools) package.
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability -Online
The above command will install ALL RSAT features in the Microsoft Catalog. If we wish to stay lightweight, we can install the package named Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0.
Commands
General Commands
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability -Online - Install Remote System Administration Tools. Which also means “Download the ActiveDirectory module”
Import-Module ActiveDirectory Imports the Active Directory Module
Get-Module -Name ActiveDirectory -ListAvailable - Locate the Active Directory module
Get-Command -Module ActiveDirectory - Lists commands for the module specified
Get-ADUser -FIlter * - List all domain users
Get-ADUser -Identity <name> - Show a specific domain user and its properties
Get-ADUser -Filter {EmailAddress -like '*greenhorn.corp'} - Filter domain users based on the EmailAddress property
Set-ADUser -Identity <UserName> -Description " Information we want in the description field" - Modify the property settings of a domain user
User Commands
New-ADUser -Name "first last" -Accountpassword (Read-Host -AsSecureString "Super$ecurePassword!") -Enabled $true -OtherAttributes @{'title'="Analyst";'mail'="f.last@domain.com"}
Add a user to AD and set attributes
New-ADUser -Name "UserName" -Surname "Last Name" -GivenName "First Name" -Office "Security" -OtherAttributes @{'title'="Sensei";'mail'="UserName@greenhorn.corp"} -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true - Create a New Domain user and set its properties such as name, password, and other attributes
Remove-ADUser -Identity <name> - Removes a user from AD with the identity of ‘name’
Unlock-ADAccount -Identity <name> - Unlocks a user account with the identity of ‘name’
Set-ADAccountPassword -Identity <'name'> -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "NewP@ssw0rdReset!" -Force) - Set the password of an AD user to the password specified
Set-ADUser -Identity amasters -ChangePasswordAtLogon $true - Force a user to change their password at next logon attempt
Group Commands
New-ADOrganizationalUnit -Name "name" -Path "OU=folder,DC=domain,DC=local" - Create a new AD OU container named “name” in the path specified
New-ADGroup -Name "name" -SamAccountName analysts -GroupCategory Security -GroupScope Global -DisplayName "Security Analysts" -Path "CN=Users,DC=domain,DC=local" -Description "Members of this group are Security Analysts under the IT OU" - Create a new security group named “name” with the accompanying attributes
Add-ADGroupMember -Identity 'group name' -Members 'ACepheus,OStarchaser,ACallisto' - Add an AD user to the group specified
GPO Commands
Copy-GPO -SourceName "GPO to copy" -TargetName "Name" - Copy a GPO for use as a new GPO with a target name of “name”
New-GPLink -Name "Security Analysts Control" -Target "ou=Security Analysts,ou=IT,OU=HQ-NYC,OU=Employees,OU=Corp,dc=INLANEFREIGHT,dc=LOCAL" -LinkEnabled Yes - Links an existing GPO to the specified OU path. The “-LinkEnabled Yes” ensures that once the link has been established, that the GPO and it’s policies are actually enabled (as it is possible for a GPLink to exist, but at the same time be disabled)
Set-GPLink -Name "Security Analysts Control" -Target "ou=Security Analysts,ou=IT,OU=HQ-NYC,OU=Employees,OU=Corp,dc=INLANEFREIGHT,dc=LOCAL" -LinkEnabled Yes - Link an existing GPO for use to a specific OU or security group.
Computer Commands
Add-Computer -DomainName 'INLANEFREIGHT.LOCAL' -Credential 'INLANEFREIGHT\HTB-student_adm' -Restart - Add a new computer to the domain using the credentials specified.
Add-Computer -ComputerName 'name' -LocalCredential '.\localuser' -DomainName 'INLANEFREIGHT.LOCAL' -Credential 'INLANEFREIGHT\htb-student_adm' -Restart - Remotely add a computer to a domain.
Get-ADComputer -Identity "name" -Properties * | select CN,CanonicalName,IPv4Address - Check for a computer named “name” and view its properties.