segunda-feira, dezembro 17, 2018
Home » Programação/ Scripts » Power Shell » Script PowerShell para alterar a senha de administrador em uma lista de máquinas

Script PowerShell para alterar a senha de administrador em uma lista de máquinas

Power ShellAqui está um script PowerShell para mudar a senha de administrador local (ou qualquer conta desejada) de uma lista de máquinas remotas.
Abra o PowerShell ISE e coloque as linhas:
$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 + “/administrator, user”)
$admin.psbase.invoke(“SetPassword”, “Whatever1”)
#$admin.psbase.CommitChanges() – I am surprised that I don’t have to do this!
# If this is for AD account, we could use PasswordLastchanged attribute. But WinNT provider does not #support the PasswordLastChanged attribute!
# I was trying to use passwordage attribute value but somehow I found it give you the value for last time, #may be because there is a delay for this attribute to propagate. So I made an “executive” decision to test #if passwordage is $null – so this may not be 100% accurate.
$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
Espero que seja útil
artigo original:

Sobre Diego Duarte

Diego Duarte atua como coordenador de suporte, é apaixonado por TI e arranha um violãozinho nos finais de semana

Gostou do conteúdo? Deixe seu comentário