Finds the built-in Guest account by the SID suffix rather than by name, so it works on a localized or renamed installation, disables it and reads the state back. A perennial line item in every hardening baseline, and one that quietly comes back after some in-place upgrades.
powershell
# Disable the Local Guest Account
# Single use case: ensure the built-in Guest account cannot log on
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
# The Guest account SID always ends in -501 (name-independent, localized OS safe)
$guest = Get-LocalUser -ErrorAction SilentlyContinue | Where-Object { $_.SID.Value -like "S-1-5-21-*-501" }
if ($null -eq $guest) {
Write-Log "Built-in Guest account not found on this host."
return
}
Write-Log "Guest account: '$($guest.Name)' enabled: $($guest.Enabled)"
if (-not $guest.Enabled) {
Write-Log "Guest account is already disabled - nothing to do."
return
}
Disable-LocalUser -SID $guest.SID
$guest = Get-LocalUser -SID $guest.SID
if (-not $guest.Enabled) {
Write-Log "Guest account disabled successfully."
} else {
Write-Log "WARNING: Guest account is still enabled!"
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Security & Auditing
Enable the Windows Firewall with PowerShell
2026-08-17Check Windows Firewall Status with PowerShell
2026-08-17Disable SMBv1 with PowerShell
2026-08-17Enforce TLS 1.2 in the Registry with PowerShell
2026-08-17Enable RDP Network Level Authentication with PowerShell
2026-08-17Audit the Local Administrators Group with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.