Reputation: 45
I am Looking for RESETING ALL PASSWORDS ON ALL LOCAL USERS on a local windows 10 machine (NOT Server). To reset passwords for all accounts on that system NOT USING Active Directory. I saw many posts that use AD to reset passwords.
I am not interested in that. Is there any alternatives to these? Using Powershell, Batch, That you guys use. Surely there is a simpler alternative for non servers.
I have seen this. But it uses alot of dependencies of LocalGroup module being installed And Exchange.
$newpwd = Read-Host "Enter the new password" -AsSecureString
Get-LocalUser | ForEach-Object {
$_ | Set-LocalUser -Password $newpwd
}
I have Seen this
# Specify the OU.
$OU = [ADSI]"LDAP://ou=West,dc=MyDomain,dc=com"
# Enumerate all objects in the OU.
$arrChildren = $OU.Get_Children()
ForEach ($User In $arrChildren)
{
# Only consider user objects.
If ($User.Class -eq "user")
{
# Set password.
$User.Invoke("SetPassword", "MyPassword")
# Expire the password.
$User.pwdLastSet = 0
$User.SetInfo()
}
}
Upvotes: 1
Views: 481
Reputation:
I agree with Windos to exclude not Enabled accounts, either via Name or Enabled property.
#Requires -RunAsAdministrator
$SecurePassword = Read-Host -Prompt "Enter password for all users" -AsSecureString
$Exclude="Administrator","Guest","DefaultAccount"
Get-LocalUser|
Where Enabled -eq 'True'|
Where {$Exclude -notcontains $_.Name}|
Set-Localuser -Password $SecurePassword
Upvotes: 1
Reputation: 1946
There is a built in module for this, that is included in Windows 10 as of 1607 (best I can tell), called Microsoft.PowerShell.LocalAccounts
What you've got there should work, the only requirement on it being that you're on version 1607 or higher. You might also want to make sure that you're only affecting enabled accounts or some some other sort of filtering so you don't accidentally change the password on something you didn't intend.
The example from the help on Set-LocalUser is:
$Password = Read-Host -AsSecureString
$UserAccount = Get-LocalUser -Name "User02"
$UserAccount | Set-LocalUser -Password $Password
If you're going to loop it, I'd personally be using Get-LocalUse
r with no arguments, piping it to where an only selecting accounts that are currently enabled.
Upvotes: 2