Solved

Powershell: Change Administrator password from txt file list

Posted on 2013-01-26
7
948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

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 40

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

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 40

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

A hard and fast method for reducing Active Directory Administrators members.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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 to another domain controller. Log onto the new domain controller with a user account t…

717 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