• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

map drives based on group membership

P

PSnewbie

#1
I need to create a logon script with powershell that will map network drives
conditionally based on group membership. We currently have a vbs script that
works but we are being told to test this using powershell. Please help!!
 

My Computer

V

Vadims Podans [MVP]

#2
mm..something like this:
$filter = "(&(objectcategory=user)(Name=$env:username))"
$ds = New-object
System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
$user = ($ds.Findone()).properties.memberof
switch -wildcard ($user) {
"*domain admins*" {net use v: \\server1\share1}
"*special group*" {net use k: \\server2\share2}
<..>
}

or like this:
$filter = "(&(objectcategory=user)(Name=$env:username))"
$ds = New-object
System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
$user = ($ds.Findone()).properties.memberof
foreach ($grouppath in $user) {
$group = ([adsi]"LDAP://$($grouppath.tostring())").sAMAccountname
switch ($group) {
"domain admins" {net use v: \\server1\share1}
"special group" {net use k: \\server2\share2}
<..>
}
}

first script will map only one network drive, the second will map drives for
each group matching in SWITCH statement.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv

"PSnewbie" <PSnewbie@xxxxxx> rakstÄ«ja ziņojumÄ
"news:067B3666-5402-44BD-B6C8-41DC484B8395@xxxxxx"...

> I need to create a logon script with powershell that will map network
> drives
> conditionally based on group membership. We currently have a vbs script
> that
> works but we are being told to test this using powershell. Please help!!
 

My Computer

A

Al Dunbar

#3
Just curious... does powershell see much service in logon scripts? I know it
is more powerful than batch, vbscript, and kixtart, but it seems to me a bit
of overkill. Other than one's familiarity with it, what powershell features
make it more suitable than the other languages for this task?

/Al

"Vadims Podans [MVP]" <vpodans> wrote in message
news:F5EF297C-893E-4535-9A3B-75DBE4959F71@xxxxxx

> mm..something like this:
> $filter = "(&(objectcategory=user)(Name=$env:username))"
> $ds = New-object
> System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
> $user = ($ds.Findone()).properties.memberof
> switch -wildcard ($user) {
> "*domain admins*" {net use v: \\server1\share1}
> "*special group*" {net use k: \\server2\share2}
> <..>
> }
>
> or like this:
> $filter = "(&(objectcategory=user)(Name=$env:username))"
> $ds = New-object
> System.DirectoryServices.DirectorySearcher([ADSI]"",$filter)
> $user = ($ds.Findone()).properties.memberof
> foreach ($grouppath in $user) {
> $group = ([adsi]"LDAP://$($grouppath.tostring())").sAMAccountname
> switch ($group) {
> "domain admins" {net use v: \\server1\share1}
> "special group" {net use k: \\server2\share2}
> <..>
> }
> }
>
> first script will map only one network drive, the second will map drives
> for each group matching in SWITCH statement.
> --
> WBR, Vadims Podans
> MVP: PowerShell
> PowerShell blog - www.sysadmins.lv
>
> "PSnewbie" <PSnewbie@xxxxxx> rakstija zinojuma
> "news:067B3666-5402-44BD-B6C8-41DC484B8395@xxxxxx"...

>> I need to create a logon script with powershell that will map network
>> drives
>> conditionally based on group membership. We currently have a vbs script
>> that
>> works but we are being told to test this using powershell. Please help!!
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)