Solved

Powershell: Change Administrator password from txt file list

Posted on 2013-01-26
7
940 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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