Ying Li at myITforum.com

PowerShell & System Center

PowerShell script to rename Local Administrator Account on a list of remote machines

This is actually a sister script for my previous post:

Change Administor Password on Remote Machines

and it is merely a one line change to accomplish the task to rename the administrator account on multiple remote machines.

#$erroractionpreference = "SilentlyContinue"

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "Account Renamed"
$c.Cells.Item(1,3) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

foreach ($strComputer in get-content C:\MachineList.Txt)
{
$c.Cells.Item($intRow,1)  = $strComputer.ToUpper()

# Using .NET method to ping test the servers
$ping = new-object System.Net.NetworkInformation.Ping

$Reply = $ping.send($strComputer)


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

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

#This is the one line change

$admin.psbase.rename("whatever")

$pwage = $admin.passwordage

If($pwage -ne $null)
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 4
$c.Cells.Item($intRow,2) = "Yes"
}
Else
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 3
$c.Cells.Item($intRow,2) = "No"
}
}
Else
{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 3
$c.Cells.Item($intRow,2) = "Not Pingable"
}

$c.Cells.Item($intRow,3) = Get-Date

$Reply = ""
$pwage = ""
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls

Posted: Aug 28 2007, 12:03 PM by yli628 | with 2 comment(s)
Filed under:

Comments

copperjohn said:

Awesome thnak you so much for this. I am just getting started with powershell.

Question:

What would the line below need-

$admin.psbase.rename("whatever")

if say i would like to rename the local admin accounts to admin.%computername%      ?

Thank you so much

# April 2, 2009 10:12 PM

yli628 said:

Something like this:

$admin.psbase.rename(admin + "." + $strComputer)

But please try it out first!

Thanks,

Ying

# April 2, 2009 10:40 PM