How to remove a local user in windows server 2016 | windows 10, this article explains one can easily create a local user account on any windows compuer, here are steps to follow.
Windows administrators as part of their routine daily tasks they deal with many servers and also create new local users on remote computers. It is easy to remove if there are only a few computers one can login and remove it, imagine if there are hundreds of servers and one has to login to each server and remove a local account means it’s an extremely painful task, The below shortcode creates a local system account with a password defined on remote computers.
Before we write a script here Microsoft has provided important commands to deal with all local accounts, here are the commands list.
Get-Command -Module Microsoft.PowerShell.localaccouts
Listing all the Local user accounts commands.
Get-Command -Module Microsoft.PowerShell.localaccounts
Removing a local account on a single computer.
Remove-LocalUser -Name John -Verbose
How to remove a local user account on remote computers
Let’s see how to remove a local account on multiple remote computers.
We need to create a file for storing all the servers or multiple machines list, I named it
as Allservers.txt for and saved it in my local machine c:\temp\Allservers.txt
$Allserers = get-content -path "C:\temp\Allservers.txt" foreach ($oneserver in $allservers) { write-host "Currently The Script is Running on"$oneserver Invoke-Command -ComputerName $onecomputer -ScriptBlock {Remove-LocalUser -Name John -Verbose} }
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply