积极答复者
域环境下为不同部门的用户映射不同的网络驱动器并重命名磁盘名称

问题
-
需求很简单,比如有A、B、C三个部门,分别对应FolderA、FolderB、FolderC三个共享目录,A部门下的所有用户开机自动映射FolderA,B部门下的所有用户开机自动映射FolderB,C部门下的所有用户开机自动映射FolderC。
有一个简单的办法是新建3条组策略分别映射FolderA、FolderB、FolderC,然后将这3条组策略分别链接到A、B、C三个部门OU上来实现功能,但是因为我们公司部门比较多,这样会多出来好多条策略,不便于管理。
请问各位前辈,有没有更简单的方式来实现为不同部门的用户映射不同的网络磁盘呢,比如通过登录脚本、分发组或者安全组的方式,请各位前辈不吝赐教,非常感谢!
答案
-
引用了 Geoff Faulkner的脚本,在此特别感谢!
我不需要的已经注释了。
'**************************************************************
'*** Login script created 01/02/2006 by Geoff Faulkner
'*** http://www.geoff-n-kris.com
'**************************************************************
on error resume next'Global variables and constants
set wshShell = CreateObject("wscript.shell")
const strDomain = "\\contoso.net\"'Get the username and other settings (type "set" at the command prompt)
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")
strComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strLogonServer = wshShell.ExpandEnvironmentStrings("%LOGONSERVER%")
strUserProfilePath = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")
strWindowsPath = wshShell.ExpandEnvironmentStrings("%WINDIR%")'**************************************************************
'*** Examples of functions
'**************************************************************
'**** map printer
'mapprinter "\\server\printershare"'**** map drive
'If not ismapped("K") then mapdrive "K:", "\\contoso.NET\shared$\Shared\" & strUserName
if not ismapped("K") then mapdrive "K:", "\\contoso.NET\shared$\Shared"'**** Check group membership to map drives or printers
'***deptA***
if ismember(strUserName, "GroupA", strDomain) then'
if not ismapped("I") then MapDrive "I:", "\\contoso.NET\shared$\Shared\deptA"
End if
'***depB***
if ismember(strUserName, "groupB", strDomain) then'
if not ismapped("I") then MapDrive "I:", "\\contoso.NET\shared$\Shared\deptB"
End if'mapprinter "\\server\printershare"
'end if'**** run an external program
'strCommandLine = "z:\folder\program.exe"
'ShellExecute = wshShell.Run(StrCommandLine)'**************************************************************
'*** Functions
'**************************************************************
Function IsMember(strUserName, strGroupName, strDomainName)
strDomainName=replace(strDomainName, "\", "/")
set Group=GetObject("WinNT:" & strDomainName & strGroupName & ",group")
IsMember=False
for each member in Group.Members
if ucase(Member.Name) = ucase(strUserName) then
IsMember=True
end if
next
End FunctionFunction IsMapped(strDriveLetter)
dim objFSO
IsMapped = false
set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.DriveExists(strDriveLetter) then IsMapped=true
End FunctionFunction MapDrive(strDriveLetter, strNetworkLocation)
dim wshNetwork
Set WshNetwork = createObject("Wscript.Network")
WshNetwork.MapNetworkDrive strDriveLetter, strNetworkLocation
End Function'Function MapPrinter(strPrinterShare)
'dim wshNetwork
'set wshNetwork = createobject("WScript.network")
'wshnetwork.addwindowsprinterconnection strPrinterShare
End Function- 已标记为答案 Linjie Huang 2017年8月15日 3:06
全部回复
-
您好 Linjie Huang,
>>有一个简单的办法是新建3条组策略分别映射FolderA、FolderB、FolderC,然后将这3条组策略分别链接到A、B、C三个部门OU上来实现功能,但是因为我们公司部门比较多,这样会多出来好多条策略,不便于管理。为了更好的解决您的问题,和您首先确认一下: 您指的是GPO多还是映射策略多?
如果是GPO多的话,您可以通过Item-Level Targeting在一条GPO中创建多条不同的组策略来映射:
Preference Item-Level Targetinghttps://msdn.microsoft.com/zh-cn/library/cc733022(v=ws.11).aspx
如果是映射策略太多的话,目前没有更加简单的build-in的方法可以实现。
>>比如通过登录脚本、分发组或者安全组的方式
脚本正常来说是可以实现的,但是需要一定的编程功底,我初步查找了一下,可能并没有完整写好的直接可以使用的这样的脚本,建议可以发到脚本论坛中咨询,是否有对应的可以实现的脚本提供。
此致
Candy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.- 已建议为答案 Candy LuoMicrosoft contingent staff, Moderator 2017年8月9日 2:51
-
您好 Linjie Huang,
很高兴听到您的问题已经解决,如果回复对您有帮助的话,建议您把回复标记为答复。
同时如果方便的话,您可以把对应的解决脚本PO上来,我相信这可以帮助到其他有相同问题的用户。
感谢您的理解与支持。
此致
Candy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com. -
引用了 Geoff Faulkner的脚本,在此特别感谢!
我不需要的已经注释了。
'**************************************************************
'*** Login script created 01/02/2006 by Geoff Faulkner
'*** http://www.geoff-n-kris.com
'**************************************************************
on error resume next'Global variables and constants
set wshShell = CreateObject("wscript.shell")
const strDomain = "\\contoso.net\"'Get the username and other settings (type "set" at the command prompt)
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")
strComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strLogonServer = wshShell.ExpandEnvironmentStrings("%LOGONSERVER%")
strUserProfilePath = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")
strWindowsPath = wshShell.ExpandEnvironmentStrings("%WINDIR%")'**************************************************************
'*** Examples of functions
'**************************************************************
'**** map printer
'mapprinter "\\server\printershare"'**** map drive
'If not ismapped("K") then mapdrive "K:", "\\contoso.NET\shared$\Shared\" & strUserName
if not ismapped("K") then mapdrive "K:", "\\contoso.NET\shared$\Shared"'**** Check group membership to map drives or printers
'***deptA***
if ismember(strUserName, "GroupA", strDomain) then'
if not ismapped("I") then MapDrive "I:", "\\contoso.NET\shared$\Shared\deptA"
End if
'***depB***
if ismember(strUserName, "groupB", strDomain) then'
if not ismapped("I") then MapDrive "I:", "\\contoso.NET\shared$\Shared\deptB"
End if'mapprinter "\\server\printershare"
'end if'**** run an external program
'strCommandLine = "z:\folder\program.exe"
'ShellExecute = wshShell.Run(StrCommandLine)'**************************************************************
'*** Functions
'**************************************************************
Function IsMember(strUserName, strGroupName, strDomainName)
strDomainName=replace(strDomainName, "\", "/")
set Group=GetObject("WinNT:" & strDomainName & strGroupName & ",group")
IsMember=False
for each member in Group.Members
if ucase(Member.Name) = ucase(strUserName) then
IsMember=True
end if
next
End FunctionFunction IsMapped(strDriveLetter)
dim objFSO
IsMapped = false
set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.DriveExists(strDriveLetter) then IsMapped=true
End FunctionFunction MapDrive(strDriveLetter, strNetworkLocation)
dim wshNetwork
Set WshNetwork = createObject("Wscript.Network")
WshNetwork.MapNetworkDrive strDriveLetter, strNetworkLocation
End Function'Function MapPrinter(strPrinterShare)
'dim wshNetwork
'set wshNetwork = createobject("WScript.network")
'wshnetwork.addwindowsprinterconnection strPrinterShare
End Function- 已标记为答案 Linjie Huang 2017年8月15日 3:06