Some usefull commands

PowerShell command to get the list of users in Active Directory - 

(get-aduser -filter *).count 


PowerShell command to get the list of active/enabled users in Active Directory - 

(get-aduser -filter *|where {$_.enabled -eq "True"}).count


PowerShell command to get the list of inactive/disabled users in Active Directory - 

(get-aduser -filter *|where {$_.enabled -ne "False"}).count


PowerShell command to get the list of computers in Active Directory -

(get-adcomputer -filter *).count 


PowerShell command to get the list of active/enabled computers in Active Directory - 

(get-adcomputer -filter *|where {$_.enabled -eq "True"}).count


PowerShell Script to get the list of inactive/disabled computers in Active Directory - 

(get-adcomputer -filter *|where {$_.enabled -ne "False"}).count


Export applied GPO to a file - 

GPResult /h c:\result.html 


To backup/export all the GPO in current domain -

Backup-GPO -All -Path "C:\GPOBackups"


PowerShell command to get the list of all installed app from the machine - 

get-itemproperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\uninstall\* | Select-object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize > C:\apps.txt


PowerShell command to find if a machine is a Windows or Linux box -

Etsn "machine name" - If there is a reply then it's a windows machine, If there is no reply then it's a Linux machine. This command will connect you to the Windows machine and will establish a session. Other commands can be executed on the machine once the session is established.


Command to print the route on a server - 

Route print 


Command to add static routes on a server - 

route ADD destination_network MASK subnet_mask  gateway_ip metric_cost 


Command to add a persistent static route to the server - 

route ADD destination_network MASK subnet_mask  gateway_ip metric_cost -p


No comments:

Post a Comment