使用Powershell远程更改本地用户密码

时间:2015-05-20 16:20:18

标签: powershell

我正在尝试使用我找到的代码。它说它正在将密码更改为我指定的帐户,但当我尝试使用该本地帐户登录该笔记本电脑时,密码未更改。 我需要能够远程将本地用户帐户的密码更改为30 +笔记本电脑,而无需登录到每个用户帐户。 任何想法为什么这不起作用?

$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) = "Password Changed"
$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 – This is very cool!
$ping = new-object System.Net.NetworkInformation.Ping

$Reply = $ping.send($strComputer)


if($Reply.status -eq "success")
{
# This is the Key Part
$admin=[adsi]("WinNT://" + $strComputer + "/LocalUser, user")

$admin.psbase.invoke("SetPassword", "Password")

$admin.psbase.CommitChanges() 

$pwage = $admin.passwordage

If($pwage.value -ne "0")
{
$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()

0 个答案:

没有答案