Solved

Powershell: Change Administrator password from txt file list

Posted on 2013-01-26
7
939 Views
Last Modified: 2013-01-26
I found the following script to change Administrator passwords on remote machines:

foreach ($strComputer in get-content C:\MachineList.Txt)
{
$ping = new-object System.Net.NetworkInformation.Ping

$Reply = $ping.send($strComputer)


if($Reply.status -eq "success")
{

$admin=[adsi]("WinNT://" + $strComputer + "/administrator, user")

$admin.psbase.invoke("SetPassword", "NewPassword")

} 

}

Open in new window


However, can someone please help me alter it. I would like an exported txt file containing a list of computers that didn't respond to the ping - so I know which computers haven't updated with the new Admin password.

Thanks in advance,

A.
0
Comment
Question by:Angeal
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:yo_bee
ID: 38822845
Are these Windows 2008 / Windows 7 machines?
Why not use Group Policy Preferences to change the local admin password?
http://abskb.wordpress.com/2009/08/30/how-to-use-group-policy-preferences-to-set-change-passwords/

GPP is your Friend.  There are so many things that GPP accomplishes that used to be painful to script.
0
 

Author Comment

by:Angeal
ID: 38822870
We have DC's running Server 2003, and the machines are a mixed bag of XP, Vista and 7.

:-/
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 38822958
GPP can be installed on all those platform.
But if you just want the script, here it is.
$out = @()

foreach ($strComputer in (get-content C:\MachineList.Txt))

{

  if ( Test-Connection $strComputer -count 1 -quiet )
  {

    $admin=[adsi]("WinNT://" + $strComputer + "/administrator, user")

    $admin.psbase.invoke("SetPassword", "NewPassword")

  }

  Else

  {

    $out += """$strComputer"" didn't respond to ping"

  }

}

$out | Out-File c:\FailedComps.txt

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 22

Expert Comment

by:yo_bee
ID: 38823032
As Foot stated you can leverage GPP as long as you have a W7 or W 2008 machine with RSAT installed and that the XP and W 2003 machines have CSE (Client Side Extension)  installed.
0
 

Author Comment

by:Angeal
ID: 38823273
Hi Footech,

The password still changed using your script, but there wasn't a c:\FailedComps.txt file.

Thanks for your help,

A.
0
 
LVL 39

Expert Comment

by:footech
ID: 38823320
You're using PS 2.0?
Do you have permissions to write to c:\?
I have tested the script and verified there were no errors, so it's just a matter of looking at your environment.  You might try specifying a different file location for the output.
0
 

Author Comment

by:Angeal
ID: 38823450
I apologize. You were right, I didn't have permissions to write to C:\.

Thanks footech for all your help!

A.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Set OWA language and time zone in Exchange for individuals, all users or per database.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now