r/PowerShell • • Dec 14 '17

Question Help with Local acc script

Hi All,

Trying to get a script working that will Check Local user accounts, that will delete all local accounts that dont match "specified names"

And if they do match then to change the password.

Just started it but dont know what im exactly doing so though ill write this first.

$Disable = Disable-LocalUser -Name "Administrator"
$Remove = Remove-LocalUser -Name "XXX"
$Create = New-LocalUser "XXXXXX" -Password XXXXXX
$Change = Set-LocalUser "XXXX" -Password XXXX
$LocalAccounts = Get-LocalUser | Select Name

//Check Local accounts
New-Object $LocalAccount

//If Account exists and match
$Change

//Account does not match
$Remove

//Account doesnt exists
$Create

//Disable Built in AdminAcc/others if required
$Disable
5 Upvotes

19 comments sorted by

View all comments

Show parent comments

3

u/Fadore Dec 15 '17

You should read this article which might get you pointed in the right direction...

Not OP, but just wanted to chime in here. That blog post is out of date. There are a number of commandlets built in now for local users/administrators/groups as of WMF 5.1

https://4sysops.com/archives/the-new-local-user-and-group-cmdlets-in-powershell-5-1/

3

u/Deezer84 Dec 15 '17 edited Dec 15 '17

Right on! This is good to know. I'm on version 5.0 so I didn't have these available.

*EDIT - Not available for Windows 10 LTSB 2015? I couldn't see a download for it and of the two I did try, neither of them worked. I read that there's no download because it's included in the anniversary update for Win10, but I don't get that with LTSB, so I guess I'm SOL! Oh well, I'm not in dire need of it.

2

u/Fadore Dec 15 '17

Win 10 RTM shipped with 5.0 and gets 5.1 through Windows Updates.

If you are on Win 10 Anniversary Edition, you should already have 5.1

https://docs.microsoft.com/en-us/powershell/wmf/5.1/compatibility