Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Last active September 3, 2018 20:03
Show Gist options
  • Select an option

  • Save mczerniawski/ab34d20b30668981f06e1b86759950cb to your computer and use it in GitHub Desktop.

Select an option

Save mczerniawski/ab34d20b30668981f06e1b86759950cb to your computer and use it in GitHub Desktop.
$ComputerName = 'SomeComputer'
$LAPSPassword = (Get-AdmPwdPassword -ComputerName $ComputerName -ErrorAction SilentlyContinue).Password
If ($LAPSPassword) {
$LocalAdminPassword = ConvertTo-SecureString -String $LAPSPassword -AsPlainText -Force
$LocalAdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$ComputerName\Administrator", $LocalAdminPassword
$LocalAdminCredential
}
Else {
Write-error "No LAPS password for computer {$ComputerName}"
$Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment