none
Update on a script - Error Handling - Success and Unsuccessful RRS feed

  • Question

  • Hello Experts,

    I need help on two things on below scipt,

    1. Logging changes on below script, like disabling the accounts are success and Account was not found/disable was not success. Need in a csv or log file so that I can review it.
    2. Remove each users from all groups. I have written it but it does not works and unable to understand why.

    Can any one help me on this, please.

    Get-Content "D:\Scripts\Adoc\Disable-Account.csv" | 
    ForEach { Get-ADUser -Filter "samaccountname -eq '$_'" -properties * } | Move-ADObject -TargetPath "OU=Disabled Users,DC=tpl,DC=local"
     -PassThru | Disable-ADAccount
    
    $users = import-csv "D:\Scripts\Adoc\Disable-Account.csv"
    
    foreach ($user in $users)
    {
    $adgroups = Get-ADPrincipalGroupMembership -Identity $user.sname
    foreach ($singlegroup in $adgroups)
    {
    if ($singlegroup.SamAccountName -notlike "*Domain Users*")
    {
        Remove-ADPrincipalGroupMembership -Identity $user.sname -MemberOf $singlegroup.SamAccountName -confirm:$false
    }
    }
    
    }
    

    Sriman Rao


    • Edited by Sriman Rao Tuesday, April 7, 2020 4:02 AM
    Monday, April 6, 2020 3:32 PM

All replies