Solved

Powershell: Change Administrator password from txt file list

Posted on 2013-01-26
7
938 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 21

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
 
LVL 21

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

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Set OWA language and time zone in Exchange for individuals, all users or per database.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

747 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

11 Experts available now in Live!

Get 1:1 Help Now