Few of the articles are posted as Images, Please use Laptop / Computers to go through the articles for best experience. For phone users, switch to Web Version

Please Share with your colleagues if you found these blogs informative. Happy Learning :-)

Powershell Script - Fetching LAPS Password from AD

 #Created By - Abhishek Bansal 

#Time Stamp - Saturday, April 1, 2023 9:27:17 AM

<#Read Me !! 

1.Script will fetch LAPS Password from AD.

2.Try Catch block is used to filter out non existing computer objects. Refer commnets as "Computer object not found" in the last column.

3.Last column blank means that computer object LAPS password is not there in AD.

For using it on any other server, just copy the entire folder, edit .ps1 into PS ISE & run it. 

#>


$inputdata = Get-Content .\Input.txt

$line = 0 

$linecount = $inputdata.count

$percentagecomplete= 0

$filename = "Output_"+(Get-Date -Format "yyyy_MM_dd")+".csv"

foreach($server in $inputdata)

{

$line++

$percentagecomplete = ($line / $linecount) * 100

$server = $server.trim()

Write-Progress -Activity "Fetching Laps Password.." -PercentComplete $percentagecomplete -Status "$line out of $linecount"

    try{

       Get-ADComputer -Identity $server -Properties * | Select Name,OperatingSystem,CanonicalName,ms-Mcs-AdmPwd  | Export-Csv ./$filename -NoTypeInformation -Append

               }

    catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]

 {

     $server | Select @{n="Name";e={$server}},@{n="OperatingSystem";e={"NA"}},@{n="CanonicalName";e={"NA"}},@{n="ms-Mcs-AdmPwd";e={"Computer object not found"}} | Export-Csv ./$filename -NoTypeInformation -Append

    }

}

No comments:

Post a Comment