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 - Removing Members (Users / Groups) from AD Group.

 #Created By - Abhishek Bansal

<#Read Me !! 

1. Script Usage - Removing Members (Users & Groups ) mentioned in Input.txt from AD Group.

2. Incase of Access Denied, run ISE as Administrator & make sure account used should have sufficient rights to remove User id from AD Group.

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


$grp = Read-Host "Enter AD Group Name = "

Get-ADGroupMember -Identity $grp | Select Name,Samaccountname | Export-Csv ./BeforeRemoval_Membership_$grp.csv -NoTypeInformation -Append

$users = Get-Content .\Input.txt

$line = 0

$linecount = $users.Count

$percentagecomplete= 0

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

foreach($userid in $users)

    {

    $line++

    $percentagecomplete = $line / $linecount * 100

    $error.Clear()

    $userid = $userid.Trim()

   Write-Progress -Activity "Removing Users..." -PercentComplete $percentagecomplete -Status "$line out of $linecount"

    try{

          Remove-ADGroupMember -Identity $grp -Members $userid -Confirm:$false

     $userid | Select-Object -Property @{n="Samaccountname";e={$userid}}, @{n="Status";e={"$userid removed succesfully on $(get-date)" }}  | Export-csv ./$filename -NoTypeInformation -Append

    }

catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]

    {

    $userid | Select-Object -Property @{n="Samaccountname";e={$userid}}, @{n="Status";e={$error.exception.message}} | Export-csv ./$filename -NoTypeInformation -Append

    }

}

Get-ADGroupMember -Identity $grp | Select Name,Samaccountname | Export-Csv ./AfterRemoval_Membership_$grp.csv -NoTypeInformation -Append


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

    }

}