суббота, 22 июля 2023 г.

Delete local users if not current and not Admin

 # Get the username of the currently logged in user

$current_username = [Environment]::UserName


# Get all local users

$local_users = Get-WmiObject -Class Win32_UserAccount -Filter  "LocalAccount='True'" | Where-Object { $_.SID -notlike "S-1-5-21-*" }


# Iterate over the local users

foreach ($user in $local_users) {

    # If the user is not the currently logged in user

    if ($user.Name -ne $current_username) {

        # Delete the user

        net user $user. Name /delete

    }

}


Комментариев нет:

Отправить комментарий