macbeth4397
Technical User
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.
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.