Creating/Managing Local User Account in Windows 10 using PowerShell

Sometimes a GUI just isnt enough and PowerShell wins overall..

I have been recently scripting the creation of several Windows 10 Local Users accounts and assigning them to Local Groups but discovered some machines didn’t have the New-LocalUser cmdlet available. Which is very annoying so in order to get around this issue I have created the following if statement to check if the module exists and install if required.

$LocalAccountModule = Get-module Microsoft.PowerShell.LocalAccounts
if ($LocalAccountModule)
{
Write-Host "Detected: Microsoft.PowerShell.LocalAccounts PowerShell Module" -BackgroundColor DarkGreen -ForegroundColor White
}
else
{
Write-Host "Not Detected: Microsoft.PowerShell.LocalAccounts PowerShell Module" -BackgroundColor DarkRed -ForegroundColor White
Install-Module  LocalAccount -Force
}

Once you have this module on your local Windows 10 client you can use the following Microsoft doc and create/manage any local accounts/group on your client desktop using PowerShell

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/?view=powershell-5.1

Regards

The Author – Blogabout.Cloud

Leave a Reply

Your email address will not be published. Required fields are marked *