Windows Vista Forums

map drives based on group membership

  1. #1


    PSnewbie Guest

    map drives based on group membership

    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 System SpecsSystem Spec

  2. #2


    Vadims Podans [MVP] Guest

    Re: map drives based on group membership

    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 System SpecsSystem Spec

  3. #3


    Al Dunbar Guest

    Re: map drives based on group membership

    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 System SpecsSystem Spec

map drives based on group membership

Similar Threads
Thread Thread Starter Forum Replies Last Post
check group membership Eero J PowerShell 3 17 Feb 2009
Script to query user information based upon group membership Brian VB Script 2 10 Nov 2008
Get group membership David Arro PowerShell 2 31 Aug 2008
Get Group Membership for a User LE2 Strat PowerShell 4 31 Jan 2008
Group Membership Don D Vista mail 0 15 Sep 2007