PowerShell is an awesome scripting platform because we don’t have to write tonnes of code, We can get things done with just a line of code.
Get all Domain Controllers in a Forest
(Get-ADForest).Domains | % { Get-addomaincontroller -filter * -server $_ | select Hostname }
Find all Server with Windows Server 2016 operating system
Get-AdComputer -filter { OperatingSystem -like "*2016*" } -Server "domainname.com" -Properties * | select Name, OperatingSystem
Find whether security patch is installed in a list of computers
Get-Content "D:\Scripts\hostnames.txt" | % { Get-HotFix -Id KB4073543 -ComputerName $_ }
We can combine this with the above 2 one-liners than using a text file.
Restart a remote computer
Restart-Computer -ComputerName "PCName" -Force
Ping all IP’s in a network
1..254 | % {Test-Connection "192.168.1.$_" -Count 1 -ErrorAction SilentlyContinue}
This will ping the whole range 192.168.1.1 – 254
Kill process
Get-Process notepad | Stop-Process
Find the active logged on user in a remote PC
Get-WmiObject -ClassName win32_computersystem -ComputerName "PCName" | select UserName
Get ‘local administrators’ group members from a remote computer
Invoke-Command -ComputerName "computerName1","ComputerName2" -ScriptBlock { Get-LocalGroupMember -Group Administrators}
Hope this will be helpful.
Thank you
Recent Comments