T O P

Finding Windows Services That Are Stopped That Should Be Started With Powershell

This was a scriptlet that got heavy use on servers and even in our RMM. It can report back services on Windows servers and desktops are are in the Stopped state that are set to Auto or Enabled.

GWMI is short for Get-WmiObject

GWMI win32_service -Filter "startmode = 'auto' AND state != 'running'"  | select DisplayName, Name, StartMode, State, ExitCode | ft -auto

Find All PST Files Via Powershell

This script came in handy for various purposes! I used this in my RMM tool to report on how many and where PST files may be lying. This was helpful for machines that were re-used. You can narrow down the folder list using the path command.

gci -path c:\ -recurse -include *.pst -erroraction 'silentlycontinue'|select-object fullname,lastwritetime | fl fullname 

Get VM Snapshots via Powershell

This is a little script / scriptlet I came up with when working at my old MSP. We unfortunately had employees who had the tendency to create snapshots in Windows Server and Hyper-V and then leave them. For long periods of time. As in months and even a year plus. These snapshots would grow and of course be a pain in the butt to merge and get rid of.

I ran this in our RMM tool and was able to set an alert or report to it. If there are no snapshots, it exits successfully (Exit 0). If there are snapshots, it says how many there are and exists with a code 1001. You can then have your RMM or log checker alert on that code.

$results=get-vmsnapshot -vmname * | Select VMName, Name, CreationTime
$count=$results | measure | Select Count
If ($count.Count -eq 0) 
	{Write-Host "No snapshots found"
	Exit 0}
Else {Write-Host $results.VMName 'has' $count.Count 'snapshots'
Exit 1001}