Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell: Change Administrator password from txt file list

Posted on 2013-01-26
7
Medium Priority
?
958 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 24

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 41

Accepted Solution

by:
footech earned 2000 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 24

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 41

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

916 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