Map Network Drive Based On ADGroup (Powershell)

 

Map Network Drive Based On ADGroup

 

$username = $env:USERNAME
$adGroups = ((New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=User)(samAccountName=$env:USERNAME))")).FindOne()).Properties.memberof | ForEach-Object { ([adsi]"LDAP://$_").cn }
foreach ($group in $adGroups)
{
switch ($group)
{
"Domain Admins" {

net use o: \\SERVER\SHARE$


}
"SecurityGroup1" {

net use * /delete /yes

net use o: \\SERVER\SHARE$

}

"SecurityGroup2" {

net use * /delete /yes

net use o: \\SERVER\SHARE$

}

"SecurityGroup3" {

net use * /delete /yes

net use o: \\SERVER\SHARE$

}


}
}