/build/static/layout/Breadcrumb_cap_w.png

Remove users who are local admin

By using a powershell scrip but 

$nomGroupe = "Administrateurs"

$nomDomaine = "xxx"


$groupeAdminLocal = [ADSI]("WinNT://./$nomGroupe,group")

$membres = $groupeAdminLocal.Invoke("Members") | foreach {

    $membre = $_

    if ($membre.GetType().InvokeMember("Class", 'GetProperty', $null, $membre, $null) -eq "user") {

        $nomUtilisateur = $membre.GetType().InvokeMember("Name", 'GetProperty', $null, $membre, $null)

        $domaineUtilisateur = $membre.GetType().InvokeMember("ADSPath", 'GetProperty', $null, $membre, $null) -replace '^WinNT://([^/]+)/.*', '$1'

        

        if ($domaineUtilisateur -eq $nomDomaine) {

            $nomUtilisateur

            Remove-LocalGroupMember -Group $nomGroupe -Member $nomUtilisateur -Confirm:$false

        }

    }

}


$listeUtilisateurs = $membres -join ', '


Write-Host "Liste des utilisateurs membres du groupe Administrateur Local du domaine $nomDomaine :"

Write-Host $listeUtilisateurs


I have an error line 13 ( cf screen copy) 


f9cSjdXiqGzyAAAAAElFTkSuQmCC

0 Comments   [ + ] Show comments

Answers (0)

Be the first to answer this question

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ