Sunday, 18 August 2013

ADDS PowerShell Commands to Expedite Your Tasks

1. How to get the DFL?
PS C:\> Get-ADDomain | findstr / 'DomainMode'
{Quoted text is case sensitive)
2. How to get the FFL?
PS C:\> Get-ADForest | findstr / 'ForestMode'
(Quoted text is case sensitive)
3. How to get the ADDefaultDomainPasswordPolicy?
PS C:\> Get-ADDefaultDomainPasswordPolicy
4. How to get the all Trusts information.
PS C:\> Get-ADTrust -f * | ft
5.Find some specific attributes for an OU users.
PS C:\> get-aduser -f * -Searchbase "ou=powershell,dc=contoso,dc=com" -pr SamAccountName,PasswordExpired,whenChanged,UserPrincipalName
6.Generate a report for all AD users samaccountname,LastLogonDate,Enabled
PS C:\> get-aduser -f * -pr lastlogondate | ft samaccountname,LastLogonDate,Enabled -auto

11.Reset the password for all users of an OU

PS C:\> Get-ADUser -Filter * -SearchBase "ou=test,dc=biz,dc=net"| Set-ADAccountPassword -NewPassword (ConvertTo-SecureString -AsPlainText monster@me123 -Force)

12.Finding Global Catalog
Get-ADForest | FL GlobalCatalogs

13. Finding last 20 events from Directory Service.
get-eventlog 'Directory Service' -newest 20 | Format-List indx, source, message

14. Find event log entries with a specific text.
Get-EventLog System | Where-Object { $_.Message -match "disk" }

15. How to get the FSMO?
>>[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() | Select-Object *owner
>>[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() | Select-Object *owner

Get-ADDomain | select PDCEmulator,RIDMaster,InfrastructureMaster | fl
Get-ADForest | select DomainNamingMaster, SchemaMaster | fl

PowerShell Function to Determine the Active Directory FSMO Role Holders - Written by Mike F Robbins

16. Reboot Report
Get-EventLog -ComputerName System | Where-Object { $_.Source -eq 'user32' } | ConvertTo-HTML | Out-File C:\Reboot.htm

17.How to unlock the AD accounts.
Search-ADAccount –LockedOut | Unlock-ADAccount

18. How to find the commands are available in a particular Module.

Get-Command -Module dnsserver

19. DCs Inventory -> Output in a CSV

Get-ADDomainController -Filter * | select name, operatingsystem,HostName,site,IsGlobalCatalog,IsReadOnly | Export-Csv c:\dcinventory.csv


No comments:

Post a Comment