Skip to content

VirtuallyThatGuy

Anything VMware , PowerCLI, PowerShell, Automation and some Windows

Menu
  • Home
  • PowerCLI
  • VMware
  • Automation
  • Windows
  • About
Menu

Windows Administrator Must Have Powershell Commands

Posted on 20 November 20224 March 2024 by VirtuallyThatGuy

This is a quick blog post about some useful windows powershell commands an administrator will find useful on a day to day basis. Share the love

CommandWhat it Does?
$psversiontableWhich version of powershell and I running
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassAllow execution of commands
Get-Printer | select Name, DriverName, PortName | Export-Csv Printers.csv -NoTypeInformationList printers on a server
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize >C:\temp\installed.txtList installed programs on server
Get-ADDomainController -Filter * | Format-table name,domain, forest,site, ipv4address, operatingsystemFind Domain Controllers
Get-Childitem -Path C:\windows -Recurse -Filter *.dllFind any *dll* on filesystem – recursive
 Get-ItemProperty .\install.xml | select *Get Detailed File information
Search-ADAccount -LockedOut | Format-Table name,lastlogondate, lockedout, objectclass, passwordexpired, passwordneverexpiresFind locked out users
Search-ADAccount -AccountDisabled -UsersOnly | FT Name,ObjectClass -AFind disabled users
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly  | FT Name,ObjectClass -AFind Users not logged in for 90 days
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |Sort-Object | FT Name,ObjectClass -AFind Users not logged in for 90 days & Sort
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |Sort-Object -property lastlogondate | FT Name,ObjectClass,lastlogondate, lockedout,  -AFind Users not logged in for 90 days & Sort by last logon 
Get-ADGroupMember -identity “Domain Admins” -recursive | select name | Export-csv -path C:\temp\Groupmembers.csv -NoTypeInformationFind “domain admins”
Get-ADComputer -Filter ‘Name -like “gbsyn*”‘ -Properties canonicalName,CN,created,IPv4Address,objectclass,OperatingSystem,OperatingSystemServicePackFind Computer with GBSYN* in the name
Get-ADPrincipalGroupMembership -identity ssi_rbailey | Sort-object | FT -property name, samaccountname -AutoSizeFind which AD groups a user is member of
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select DistinguishedName,Enabled | Export-Csv c:\temp\result.csv -NoTypeInformationFind Disabled Domain admins
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select Name,SamAccountName,Enabled, objectclass | sort-object -Property nameFind Disabled Domain admins & Sort
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select Name,SamAccountName,Enabled, objectclass | sort-object -Property name | Export-CSV C:\temp\DisabledDomainAdmins.csvFind Disabled Domain admins & Sort & Export to CSV
Get-ADGroupMember -Identity “GROUPNAME” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $true}} | Select Name,EnabledFind members in a group
Get-Eventlog application -Newest 2000 | Where-Object {$_.entryType -Match “Error”}Find Latest errors in Eventlog
Get-Eventlog system -Newest 2000 | Where-Object {$_.entryType -Match “Error”}Find Latest errors in Eventlog
cd hkcu:Navigate Registry like filesystem
ps | sort –p ws | select –last 5Find the five processes using the most memory
Restart-Service DHCPRestar DHCP service
Get-ChildItem – ForceList all items within a folder
Get-ChildItem –Force c:\directory –RecurseList all items within a folder & all subfolders
Get-WmiObject -Class Win32_Service -Filter “state = ‘running’ and startmode = ‘auto’” | Select-Object name, startmode, description | Format-table -AutoSizeGet list of Services that start automatically
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’)Load SQL modules into memory 
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null
$s = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) “servername”
$dbs=$s.Databases
$dbs | SELECT Name, Collation, CompatibilityLevel, AutoShrink, RecoveryModel
Discover SQL instances
Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name -eq”VmRemovedEvent”} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 19Find Vm’s Remove last 10 days
$wu = new-object -com “Microsoft.Update.Searcher”
 $totalupdates = $wu.GetTotalHistoryCount()
 $all = $wu.QueryHistory(0,$totalupdates)
 # Define a new array to gather output
 $OutputCollection=  @()        
Foreach ($update in $all)
    {
    $string = $update.title
    $Regex = “KB\d*”
    $KB = $string | Select-String -Pattern $regex | Select-Object {$_.Matches }
     $output = New-Object -TypeName PSobject
     $output | add-member NoteProperty “HotFixID” -value $KB.‘ $_.Matches ‘.Value
     $output | add-member NoteProperty “Title” -value $string
     $OutputCollection += $output
    }
 # Output the collection sorted and formatted:
$OutputCollection | Sort-Object HotFixID | Format-Table -AutoSize
Write-Host “$($OutputCollection.Count) Updates Found
Command to get all Installed KB (Windows Update) from Server
frminst.exe /remove=agentForce uninstall McAffee when managed by another server (managed mode)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

When autocomplete results are available use up and down arrows to review and enter to go to the desired page. Touch device users, explore by touch or with swipe gestures.

Recent Posts

  • vROps: Management Pack Troubleshooting
  • Migrate VSS Config to Another Host Using Powercli
  • Windows AD {Active Directory} (PowerShell) samples
  • Migrate VMs Between vCentres Using Powershell or PowerCLI
  • Set VM Tools to Update Automatically on VM Reboot using powershell

Recent Comments

  • JB on Script: How to get VM with Tag Assignment and export results to csv using PowerCLI or Powershell
  • DL on How to change VCSA root password and bypass BAD PASSWORD: it is based on a dictionary word for vCenter VCSA root account warning
  • 360coolp on How to change VCSA root password and bypass BAD PASSWORD: it is based on a dictionary word for vCenter VCSA root account warning
  • Yogesh on ESXi 8.x, 7.x, 6.x Service sfcbd-watchdog Not Running / Fails to Start – VirtuallyThatGuy
  • VirtuallyThatGuy on ESXi 8.x, 7.x, 6.x Service sfcbd-watchdog Not Running / Fails to Start – VirtuallyThatGuy

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017

Categories

  • Automation
  • PowerCLI
  • VMware
  • Windows
© 2025 VirtuallyThatGuy | Powered by Superbs Personal Blog theme