Enable Disabled LOCAL accounts with Powershell

JakeBanzai
JakeBanzai used Ask the Experts™
on
I need to enable a special local account on about 2000 PCs that were locked out during a security scan. I also would like to remove the "User Must Change Password At Next Logon" field. I've tried the following -

Get-WmiObject Win32_UserAccount -computername (Get-Content C:\ps\computers.txt) -filter "LocalAccount=True"|where {$_.name -eq "SDC_Admin"|%{$_.disable=$true;}}

But I receive the following error

Property 'disable' cannot be found on this object; make sure it exists and is settable.
At C:\ps\accounts.ps1:1 char:145

However, enable and disable appears to be the syntax I've found in my research, nevertheless I receive the error.

Any suggestions appreciated.

Jake
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dale HarrisProfessional Services Engineer

Commented:
All the nuts and bolts you're going to need are here:
http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/22/use-powershell-to-enable-or-disable-a-local-user-account.aspx

The most important method on top of all the code required to run it is here:
$ObjUser = [ADSI]"WinNT://$computer/$user"

When referring to local accounts, your best bet is to use a list of IPs or Computernames in a text file, and pull them into a variable you can use in a foreach.

Then specify statically the account and basic attributes.

Don't use the Win32_UserAccount way.

Good luck!

-DH

Author

Commented:
Thanks for the input.

You'll notice I am using a text file to populate the computername: -computername (Get-Content C:\ps\computers.txt). This portion of the script works perfectly scrolling the following in ISE:

AccountType : 512
Caption     : PC8874F-139670\SDC_Admin
Domain      : PC8874F-139670
SID         : XXXXXXXXXXXXXXXXXXXXXX
FullName    :
Name        : SDC_Admin

I thought I had statically specified the account and basic attributes here:

-filter "LocalAccount=True"|where {$_.name -eq "SDC_Admin"|%{$_.Lockout=$false;$_.put()}}

Thanks again for the help.

Author

Commented:
http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/22/use-powershell-to-enable-or-disable-a-local-user-account.aspx

 
This is link helpful, but the last thing I want to do on all these computers is reset the password. Simply want to renable them and ensure the "User Must Change Password at Next Logon" option is UNCHECKED.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Dale HarrisProfessional Services Engineer

Commented:
Does this work?

Get-WmiObject Win32_UserAccount -computername (Get-Content C:\ps\computers.txt) -filter "LocalAccount=True"|?{$_.name -eq "SDC_Admin"} |%{$_.disabled=$false;$_.put()}
Raheman M. AbdulMessaging and Directory Services

Commented:
Does this work?

Get-WmiObject Win32_UserAccount -computername (Get-Content C:\ps\computers.txt) -filter "LocalAccount=True"|?{$_.name -eq "SDC_Admin"} |%{$_.disabled=$false;$_.passwordChangeable=$true;$passwordrequired=$true;$_.put()}

Author

Commented:
Marahman3001 - this one must be close, it runs without error - but does not re-enable / unlock the SDC_Admin account.

thanks for the help
Messaging and Directory Services
Commented:
if you want to unlock the account
try
Does this work?

Get-WmiObject Win32_UserAccount -computername (Get-Content C:\ps\computers.txt) -filter "LocalAccount=True"|?{$_.name -eq "SDC_Admin"} |%{$_.disabled=$false;$_.passwordChangeable=$true;$passwordrequired=$true;$disabled=$false;$_.put()}

Author

Commented:
Marahman3001 - THANK YOU! That unlocked the local account on the PCs I was testing. This will get me some breathing room while I figure out how to clear the "User Must Change Password at Next Logon" option on the account.

Thanks again - I'll look over the code and figure out where I was going wrong!

Jake
Raheman M. AbdulMessaging and Directory Services

Commented:
My pleasure
Thanks Jake
Mohammed Abdul Raheman

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial