Thursday, 14 May 2026

Disable the Accounts, Move the account to UnSync OU.

             $users = Get-Content C:\Temp\kumar\admaccount1.txt


            $targetou = "OU=Unmanaged Users,DC=Test,DC=com"


                        foreach ($usr in $users){


                        $userdn = Get-Aduser $usr -Properties * | Select-Object -ExpandProperty DistinguishedName


                            if ($usr){


                                Disable-ADAccount $usr


                            if ($usr) {


                            Move-ADObject -Identity $userdn -TargetPath $targetou


                                }


                                }


                                }

No comments:

Post a Comment