Use "Client Site Name" in Group Policy Preferences

In Active Directory, you can map IP addresses to Client Sites.

enter image description here

...and then you can map Group Policy objects to sites.

enter image description here

Which is great and all, but I have a client that is growing rapidly, and they expect to have hundreds of sites in the next year or two.

Our naming standard is loosely based on LOCODE, so every site is 7 characters--for example 'USHQZOF'. That prefix is used to name every machine.

I'm getting sick of creating the same basic policy everywhere.

It literally follows the format:

  • Map drive O to \\USHQZOFSRV01\officeshare
  • Map primary printer to \\USHQZOFSRV01\copier

I'd really love it if I could create a policy where I can say:

  • Map drive O to \\(site-name-from-ad)SRV01\officeshare
  • Map primary printer to \\(site-name-from-ad)SRV01\copier

...and be done with it for good.

It appears you can use a ton of environment variables in your Group Policy Preferences (https://technet.microsoft.com/en-us/library/Cc753915.aspx), but I don't see anything for the Client Site Name.

Am I out of luck, or do I need to go 'old school' and call a cscript/vbscript file during login that looks it up and maps the appropriate items?

(edit: I know it can be done with a VBS file--I've done it before. It just seems...unclean...)


is my first time i try to help

I had this problem also, and i solve it using dns defaul behavior Prioritizing local subnets https://technet.microsoft.com/en-us/library/cc787373(v=ws.10).aspx

So in your case just need to create a A Record for your sites fs Servers with the name SRV01

And then just create one gpo to mount And add the default print with srv01\ And link it to every site

And when a client in the site ask for srv01, the dns will return the correct ip address for srv01 for that site


if you are still curious about a VBS, this code will set the site name to a system variable.

'--- Get Site name ---
Set strSysinfo = CreateObject("ADSystemInfo")
strCurrentSite=strSysinfo.Sitename

'--- Write site name to system variables ---
Set objShell = CreateObject("WScript.Shell")
Set objSystemEnv = objShell.Environment("SYSTEM")
objSystemEnv("SiteName") = strCurrentSite

'--- Clean ---
Set strSysinfo = Nothing
Set objShell = Nothing
Set objSystemEnv = Nothing