Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mapping network drive after log in.. VBS to Powershell

Status
Not open for further replies.

macbeth4397

Technical User
Nov 23, 2011
1
AU
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
else
'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")
else
'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
}else{
$returnVal = 0
return $returnVal = 0

}

}else{
$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.

 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top