Skip to content

Instantly share code, notes, and snippets.

@mortenya
Last active August 29, 2015 14:15
Show Gist options
  • Save mortenya/fe07bb219925e114fcf3 to your computer and use it in GitHub Desktop.
Save mortenya/fe07bb219925e114fcf3 to your computer and use it in GitHub Desktop.
Incomplete, but the point is to change the local admin password on all computers, would then need to drop that password and $env:COMPUTERNAME into an encrypted spreadsheet so that you could get it.
$Computers = Get-ADComputer -Filter * | Where distinguishedName -NotLike "*DC*"
$user = Get-WmiObject Win32_UserAccount -Filter "LocalAccount=true" | where { $_.Name -eq 'Administrator' }
$Count = 1
$CharSet1 = [Char[]]"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
ForEach ($c in $Computers)
{ Write-Progress -Id 1 -Activity "Changing Server Passwords" -Status "Current Progress: $Count of $($Servers.Count): $($Server.Name)" -PercentComplete (($Count / $c.Count) * 100)
$Ping = Test-Connection $c.Name -Count 2 -Quiet
If ($Ping) {
$Password = (($CharSet1 | Get-Random -Count 5) -join "") + " " + `
(($CharSet1 | Get-Random -Count 5) -join "") + " " + `
(($CharSet1 | Get-Random -Count 5) -join "")
Try {
$User = [ADSI]"WinNT://$($Server.Name)/$($user),user"
$User.SetPassword($Password)
$User.SetInfo()
Start-Sleep -Milliseconds 500
}
Catch {
Write-Warning "Unable to change password for "$($c.Name)" because "$($Error[0])""
}
}
Else {
Write-Warning "Unable to ping $($Server.Name)"
}
$count++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment