Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

mapping network drive after log in.. VBS to Powershell

mapping network drive after log in.. VBS to Powershell

mapping network drive after log in.. VBS to Powershell

I am trying to convert a log on script for mapping drive .. the script basically input the username from og in and map the network drive available drive available for the username on the basis of group membership.

So the VBScript for it is :

    Dim objGroupList 'Used for the isMember function.

    set WshShell = WScript.CreateObject("WScript.Shell")

    StaffServer = "it-staff"
    LibshareServer = "it-staff"
    CoursematDrive = "digiit\ias\staff"
    ShellUserName = WshShell.ExpandEnvironmentStrings("%username%")
    ShellUserDomain = WshShell.ExpandEnvironmentStrings("%userDomain%")
    ShellUserDNSDomain = WshShell.ExpandEnvironmentStrings("%userDNSDomain%")
    ShellSystemRoot = WshShell.ExpandEnvironmentStrings("%SystemRoot%")
    ShellSystemDrive = WshShell.ExpandEnvironmentStrings("%SystemDrive%")
    ShellWinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
    ShellProgramFiles = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
    ShellComputerName = WshShell.ExpandEnvironmentStrings("%ComputerName%")
    ShellTempFolder = WshShell.ExpandEnvironmentStrings("%temp%")
    ShellTmpFolder = WshShell.ExpandEnvironmentStrings("%tmp%")
    ' This variable stores the AD Object for the current user.  Used for
    ' the isMember function.
    set UserADObject = getADObject(ShellUserDomain & "\" & ShellUserName)

' Thunderbird one: Initialise Main program!
if isMember("lib_win2k", UserADObject) then
      ' Members have nothing done to them
         'Non-members get favourites moved.
         'Call WindowsFavouritesLogon()   
         Call FirefoxBookmarksLogon()                                         
end if

' Map Network Drives below here

if isMember("it_itshare_ro", UserADObject) then
         'Members of the lib_libshare_ro Group get the mapped drive
     call DeleteDriveMapping("I:")
         call MapDrive("I:", itshareServer, "itshare")
         'Non-members simply fall trough...                                            
end if

Now when i am doing it to power shell I did :

$strName = $env:username

function get-GroupMembership($DNName,$cGroup){
 $strFilter = "(&(objectCategory=User)(samAccountName=$strName))"

 $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
 $objSearcher.Filter = $strFilter

 $objPath = $objSearcher.FindOne()
 $objUser = $objPath.GetDirectoryEntry()
 $DN = $objUser.distinguishedName
 $strGrpFilter = "(&(objectCategory=group)(name=$cGroup))"
 $objGrpSearcher = New-Object System.DirectoryServices.DirectorySearcher
 $objGrpSearcher.Filter = $strGrpFilter
 $objGrpPath = $objGrpSearcher.FindOne()
 If (!($objGrpPath -eq $Null)){
  $objGrp = $objGrpPath.GetDirectoryEntry()
  $grpDN = $objGrp.distinguishedName
  $ADVal = [ADSI]"LDAP://$DN"
  if ($ADVal.memberOf.Value -eq $grpDN){
   $returnVal = 1
   return $returnVal = 1
   $returnVal = 0
   return $returnVal = 0
   $returnVal = 0
   return $returnVal = 0

$result = get-groupMembership $strName "lib_staff"
if ($result -eq 'true′) {
 $(New-Object -ComObject WScript.Network).RemoveNetworkDrive("L:");
 $(New-Object -ComObject WScript.Network).MapNetworkDrive("L:", "\\lin-staff\general");

But the power shell script only map the user it does not do th 'ismember' function or does not check whether the user is member of which group..

is there any way i can extract the group membership from the username and then map according to the group membership.


RE: mapping network drive after log in.. VBS to Powershell

Have you looked into Group Policy preference for drive mapping? I would think it would be easier to maintain in the long run than a custom powershell script.

RE: mapping network drive after log in.. VBS to Powershell

powershell is so slow to load, i would leave it in vbscript.
besides, anyone who authors a logonscript which you have to modify everytime you want to change / add / remove a drive mapping needs their head read

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close