← script library

Disable the Guest Account with PowerShell

Security & AuditingAugust 17, 2026

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.

Ready when you are.

Try ServerEngine free for 7 days.