The following
table lists all the cmdlets that are available in this release of the Active
Directory module in Windows Server 2008 R2.
PS C:\>
Get-ADDomain
Retrieve
properties for the Administrators group:
PS
C:\> Get-ADGroup -Identity Administrators | Get-Member
Retrieve
ALL properties for the Administrators group:
PS
C:\> Get-ADGroup -Identity Administrators -Properties *| Get-Member
Retrieve
the extended properties "Organization" and the default properties for
the user: Rakeshc:
PS
C:\> GetADUser -Identity rakeshc –Properties Organization
Retrieve
the properties with LDAP display names of "hcluser" and "messaging",
for the user: rakeshc:
PS
C:\> GetADUser -Identity rakeshc -Properties hcluser, messaging |Get-Member
PS C:\> New-ADGroup -Server
DC1.msexchangequery.com -Path "OU=Exchange,DC=dc" -Name AccountLeads
-GroupScope DomainLocal -GroupCategory Distribution
PS C:\>
New-ADGroup -Name "Lync Admins" -SamAccountName RODCAdmins
-GroupCategory Security -GroupScope Global -DisplayName "Lync
Administrators" -Path "CN=Exchange,DC=dc,DC=Com" -Description
"Members of this group are Lync Administrators"
Remove
the group that has samAccountName 'messaging':
PS
C:\> remove-adgroup messaging
Get
all groups whose name starts with 'messaging' and remove them:
PS
C:\> get-adgroup -filter 'Name -like "messaging"' | remove-adgroup
Remove
a group, the cmdlet will prompt for a name:
PS
C:\> remove-adgroup
PS C:\> Get-ADGroup lyncAdmin -Properties
Description
Adds
the user accounts with SamAccountNames User01 and User02 to the group messaging:
PS
C:\> Add-ADGroupMember messaging User1,User2
Get
all the members of the administrators groups using the default behavior:
PS
C:\> get-adgroupmember -Identity "messaging"
Remove
the user with samAccountName 'FredB' from the group 'messaging':
PS
C:\> remove-adgroupmember -Identity "messaging" -Member "rakeshc"
Remove
the users with samAccountNames 'administrator' and 'rakeshc' from the group 'messaging'
and don't ask to confirm:
PS
C:\> remove-adgroupmember "messaging"
"administrator","rakeshc" -Confirm:$false
Retrieve
all the groups the administrator is a member of:
PS
C:\> get-adprincipalgroupmembership -Identity Administrator
PS C:\>
Get-ADUser rakeshc
PS C:\>
Get-ADUser –Filter {Surname –eq “chaturvedi”}
PS C:\>
Get-ADUser –Filter {GivenName –eq “Rakesh”}
PS C:\>
Get-ADPrincipalGroupMembership –Identity rakeshc
PS C:\>
Remove-ADGroupMember –Identity “Group Name” –Member “rakeshc”
PS C:\>
Get-ADPrincipalGroupMembership –Identity khess
PS C:\>
New-ADUser –Name “Rakesh Chaturvedi” –GivenName Rakesh –Surname Chaturvedi
–UserPrincipalName rakeshc@msexchangequery.com –SamAccountName rakeshc
PS C:\>
Get-ADUser rakeshc
PS C:\>
Add-ADGroupMember CS-Administrator rakeshc
PS C:\>
New-ADUser –Name “Rakesh Chaturvedi” –GivenName Rakesh –Surname Chaturvedi
–UserPrincipalName rakeshc@msexchangequery.com –SamAccountName rakeshc –Enabled
1 –AccountPassword (Read-Host –AsSecureString “Password”)
PS C:\>
Search-ADAccount –AccountDisabled –UserOnly |FT Name
PS C:\>
Set-ADAccountPassword –Identity rakeshc –NewPassword (Read-Host –AsSecureString
“New Password”) –OldPassword (Read-Host –AsSecureString “Old Password”)
PS C:\>
Enable-ADAccount –Identity rakeshc
PS C:\>
Search-ADAccount –AccountDisabled –UserOnly |FT Name
PS C:\>
Search-ADAccount –LockedOut –UsersOnly |FT Name
PS C:\>
Unlock-ADAccount –Identity rakeshc
PS C:\> Unlock-ADAccount
–Identity (Read-Host “rakeshc”)
PS C:\>
Disable-ADAccount –Identity rakeshc
PS C:\>
Enable-ADAccount -Identity Rakeshc
PS C:\>
Remove-ADUser rakeshc
PS C:\>
Remove-ADUser rakeshc
PS C:\>
Set-ADAccountPassword -Identity rakeshc
PS C:\>
$newPassword = (Read-Host -Prompt "Provide New Password"
-AsSecureString)
PS C:\> Set-ADAccountPassword
-Identity JMarbles -NewPassword $newPassword –Reset
PS C:\>
Set-ADAccountPassword -Identity JMarbles -OldPassword (ConvertTo-SecureString
-AsPlainText "0ldPaZZw0rd" -Force) -NewPassword
(ConvertTo-SecureString -AsPlainText "p@ssw0rd2" -Force)
PS C:\>
Get-ADDomain “msexchangequery.com” –Server “DC1” –Credential
“msexchangequery.com\Administrator”
PS C:\>
Get-ADUser rakeshc –Server “Dc1” –Credential “msexchangequery.com\Administrator”
PS C:\>
Add-ADComputerServiceAccount -Computer Computer1 -serviceAccount SvcAc1
PS C:\> Add-ADComputerServiceAccount -Computer Computer1 -serviceAccount
SvcAc1,SvcAc2