Some helpful commands for PowerShell Beginner.

Some Commands/Scripts require Powershell version 3.0 or above.

Table of Contents


Back to top 

Applies to

  • Windows Server 2008,
  • Windows Server 2008 R2,
  • Windows Server 2012,
  • Windows Server 2012 R2


Back to top 


Powershell Function (Basics)

Powershell .NET Namespace


Back to top 

Managing Modules

How to find loaded Modules?


How to find available modules?

Get-Module -ListAvailable

How to import a Module?

import-module activedirectory

How to get help for Modules?

Get-Help about_module

How to import All modules all together.

Get-Module -ListAvailable | Import-Module -Verbose

How to find particular module commands ?

Get-Command -Module activedirectory

How to find Module name of the CMDLETs

get-command get-*


Back to top 

Getting Help

How to get Particular CMDLET help?

get-help Get-Service 

get-help Get-Service -Full

get-help Get-Service -Detailed

get-help Get-Service -ShowWindow

get-help Get-Service -Online

get-help Get-Service -Examples

How to get full help  of a Module (e.g. grouppolicy, activedirectory)

GCM -Module grouppolicy | Foreach {get-help $ -Examples} GCM -Module activedirectory | Foreach {get-help $ -Examples}   

How to Update Powershell Help

Update-Help -Force


Back to top 

Powershell environment

Powershell Color Code-MSDN

Helpful !!! when we are created HTML report using Powershell.


Upgrading the Powershell Version 2 to 4 on 2008 R2

How to check Powershell Path


How to find Powershell Alias


How to find a particular Alias

#GAL is the Alias of  Get-Alias
GAL -Definition Get-Service

How to check Powershell Version?

Environment Variable to get PowerShell Version





$host.Version.Major OR $psversiontable OR Get-Host | Select-Object Version

How to change the execution Policy?

Set-ExecutionPolicy Unrestricted

Set-ExecutionPolicy Unrestricted CurrentUser

#Without Prompt

Set-ExecutionPolicy Unrestricted -force

#Recomendad seeting is Allsigned/Remotesigned

#There are Five Policies-Restricted(Default Setting),Unrestricted,Allsigned,

  Remotesigned & Bypass.

See the details about Powershell Execution Policy.

How to Test Performance of a Powershell Script?

Measure-Command { .\DCInventory.ps1 }

See the execution time of DCInventory.ps1

How to use page break like More "Switch" at cmd Prompt.

Get-Service | Out-Host -Paging


Back to top 

System Management

Event Log

When & who rebooted the system? (Below simplified command is required Powershell 3 & above, "?" is used for "where")

Get-EventLog -log System | ? EventID -EQ 12 | select username,TimeGenerated


Get-EventLog -log System | where EventID -EQ 12 | select username,TimeGenerated


Get-EventLog System | ? Source -eq user32 | select MachineName,TimeGenerated,UserName,Message -First 1

How to find LastBootupTime ? (Required Powershell 3 & above)

Get-CimInstance Win32_OperatingSystem | select  csname,LastBootUpTime

Server Services Inventory.

#Total Nos. of Services.
PS C:\> $all = Get-Service
PS C:\> $all.Count

 PS C:\> Get-Service | measure | select count

#Stopped Services
PS C:\> $all | ? status -NE 'running'
#Running Services
PS C:\> $all | ? status -NE 'stopped'
#Count All Running Services
PS C:\> $allRunning = $all | ? status -NE 'stopped'
PS C:\> $allRunning.Count
#Count All stopped Services
PS C:\> $allstopped = $all | ? status -NE 'running'
PS C:\> $allstopped.Count

Getting Computer OS & SP for multiple Computers

$computers = get-content C:\computers.txt
Get-WmiObject win32_operatingsystem -ComputerName $computers  | select CSName,Caption, CSDVersion | FL

You can query multiple systems & that script is available in Microsoft Script Center.

Installed Hotfix/Update/ServicesPack Report.

gwmi -Query "Select * from Win32_QuickFixEngineering"
gcim -Query "Select * from Win32_QuickFixEngineering"
systeminfo | find ": KB"
wmic qfe


Back to top 


How to enable WinRM ?

winrm qc


Back to top 

Directory Servcies

Verify ForestPrep, Domainprep & Rodcprep Result

Finding FSMO For Multi Domains

You no need to change anything in that Script; also AD module is not required. Powershell internals

Find attributes from bulk computers.

Function Com-Attrs {
$Computers= get-content C:\computers.txt
foreach ($Computer in $computers)
Get-ADComputer $Computer | 
Select-Object DNSHostName,Enabled,SamAccountName
Com-Attrs | FT -AutoSize

Get & Set the RDP for multiple Computers

Get the Internet Explorer Version for multiple Computers

Powershell Workflow-Scan media files into TerraByte Storage

WSMAN Registry key


How to check WINRM Settings.

winrm get winrm/config

How to change "MaxEnvelopeSizekb" value ?

winrm set winrm/config @{MaxEnvelopeSizekb="1024"}

Remotely getting NTP Servers from PDC - Below is the Code

$computer = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().PdcRoleOwner.Name 
$Reg = [Microsoft.Win RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer) 
$RegKey= $Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters"
$NTP = $Regkey.GetValue("NtpServer"
Write-host $NTP -BackgroundColor DarkMagenta -ForegroundColor Cyan

DCs Inventory 

[system.directoryservices.activedirectory.domain]::GetCurrentDomain().DomainControllers | Select Name,IPAddress,OSVersion,SiteName | FT -AutoSize

Getting the Domain Functional level


Getting the Forest Functional level


Getting the Trust


How to restore the ActiveDirectory Objects

. See the Tombstone
Get-ADObject -Filter {LastKnownparent -eq "OU=ADFS,DC=Contoso,DC=COM"} -IncludeDeletedObjects
 Restore the Object
Get-ADObject -Filter {LastKnownparent -eq "OU=ADFS,DC=Contoso,DC=COM"} -IncludeDeletedObjects | Restore-ADObject -NewName bshwjt

See the deleted Objects From Active Directory Recycle BIN

##Prerequsites : . WIndows 2008 R2 DFL 2) Active Directory Recycle Bin
Get-ADObject –SearchBase “CN=Deleted Objects,DC=Contoso,DC=Com” –ldapFilter “(objectClass=*)” -includeDeletedObjects | FL *

Total Sites


All Sites Name




Nos. of DCs


Logon Information

Get-ItemProperty -Path 'HKCU:\Volatile Environment'

How to check Active directory recycle bin enabled or not ?

Get-ADOptionalFeature -F 'name -like "Recycle Bin Feature"' | Select-Object EnabledScopes

Active directory recycle bin is disabled ,If above command output is empty.


Get the permission of an User for an OU

ipmo activedirectory

cd ad:

$ACL = get-acl 'AD:\OU=cno,ou=cno,Dc=contoso,DC=com' | select -exp Access | ? IdentityReference -match 'kerbtest'



Back to top 

Remote Management

Installation and Configuration for Windows Remote Management

Smallest PS Script for Get the WINRM Status of Multiple Computers

Authentication for Remote Connections


Back to top 

Patching and Hotfixes

Get the latest patching Date

Get-HotFix | Select HotFixID,InstalledOn,InstalledBy -First 1


How to check specific DNS Reverse Lookup Zone present or not?

dnscmd ANA-DC003 /enumzones /reverse | Select-String -Pattern ''


Back to top 


How to test Port?

$SOC = New-object Net.Sockets.TcpClient

$SOC.Connect("    1",636)



Back to top 

See Also


Back to top 

Another languages available


Back to top 

Gallery downloads


Back to top