Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable local user fails #2

Open
Zinkelburger opened this issue Aug 8, 2024 · 0 comments
Open

Disable local user fails #2

Zinkelburger opened this issue Aug 8, 2024 · 0 comments

Comments

@Zinkelburger
Copy link
Owner

The current disable local user fails for me when I try it on an AWS machine. I swear it worked for me previously, but it is easily replaced by

# Get the current user and set excluded accounts
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name.Split('\')[1]
$excludedAccounts = @("black team") # Add any other accounts to this array if needed

# Disable local accounts
Get-LocalUser | ForEach-Object { 
    if ($_.Name -ne $currentUser -and $excludedAccounts -notcontains $_.Name) {
        Disable-LocalUser -Name $_.Name
        Write-Host "Disabled local account: $($_.Name)"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant