|
| 1 | +function Get-LapsAdmPwd { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + This script reads ms-Mcs-AdmPwd and ms-Mcs-AdmPwdExpirationTime attributes if user have all extended rights on computer account without |
| 5 | + local admin privileges. |
| 6 | + |
| 7 | + .PARAMETER LapsInstalled |
| 8 | + The parameter LapsInstalled is used to define the AdmPwd.PS module is installed. |
| 9 | +
|
| 10 | + .PARAMETER OtherComputer |
| 11 | + The parameter OtherComputer is used to query for other computer. |
| 12 | +
|
| 13 | + .EXAMPLE |
| 14 | + PS C:\> Get-LocalAdminPassword –LapsInstalled |
| 15 | + PS C:\> Get-LocalAdminPassword –LapsInstalled -OtherComputer |
| 16 | + |
| 17 | + .NOTES |
| 18 | + Windows Powershell should be run as domain user rights. If GPO is applied which only specified users join local adminstrators group , this script could be executed without admin rights. |
| 19 | +
|
| 20 | + If running scripts is disabled on your system, execute following command firstly. |
| 21 | + Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser |
| 22 | +
|
| 23 | + #> |
| 24 | + param ( |
| 25 | + |
| 26 | + [switch]$LapsInstalled, |
| 27 | + [switch]$OtherComputer |
| 28 | + ) |
| 29 | + begin { |
| 30 | + |
| 31 | + Write-Host "Obtaining ms-mcs-admpwd attribute value via MS-DS-Machine-Account-Quota" -ForegroundColor Green |
| 32 | + } |
| 33 | + process { |
| 34 | + |
| 35 | + $dPath = $env:USERPROFILE |
| 36 | + Write-Host "UserProfile: $dPath" -ForegroundColor Yellow |
| 37 | + $hName = $env:COMPUTERNAME |
| 38 | + Write-Host "Computername: $hName" -ForegroundColor Yellow |
| 39 | + Write-Host "[*] Did you install LAPS management powershell module? $LapsInstalled" |
| 40 | + if ($LapsInstalled) { |
| 41 | + Import-Module AdmPwd.PS |
| 42 | + Write-Host "[*] Would you like to query another computer account you added yourself? $otherComputer" |
| 43 | + if ($OtherComputer) { |
| 44 | + $computer = Read-Host -Prompt "[*] Computer name " |
| 45 | + Get-AdmPwdPassword -ComputerName $computer | format-list -Property ComputerName, ExpirationTimestamp, Password |
| 46 | + |
| 47 | + } else { |
| 48 | + Get-AdmPwdPassword -ComputerName $hname | format-list -Property ComputerName, ExpirationTimestamp, Password |
| 49 | + |
| 50 | + } |
| 51 | + } else { |
| 52 | + Write-Host "[-] Cancelled!" -ForegroundColor Red |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments