I'm very new in powershell. I'm trying to create a script to disable the AD account and do multiple tasks in it.
I'm stuck in the part where i want to assign all the Distribution lists and Security Groups managed by the user to his manager. Below is the script, any help would be appreciated.
$SamAccountName = Read-Host "Enter the username"
$ManagedObjects = Get-ADUser $SamAccountName -Properties managedObjects |select -ExpandProperty managedObjects
$Manager = Get-ADUser $SamAccountName -Properties manager | Select -ExpandProperty Manager
$ManagedObjects | ForEach-Object {
Set-ADGroup -Identity $_.Group -ManagedBy ($Manager.DistinguishedName)
}