We help IT Professionals succeed at work.

Enable Disabled LOCAL accounts with Powershell

JakeBanzai
JakeBanzai asked
on
6,765 Views
Last Modified: 2012-07-25
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

Dale HarrisProfessional Services Engineer
CERTIFIED EXPERT

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.
Dale HarrisProfessional Services Engineer
CERTIFIED EXPERT

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
CERTIFIED EXPERT

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
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

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
CERTIFIED EXPERT

Commented:
My pleasure
Thanks Jake
Mohammed Abdul Raheman

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions