Author Topic: Get computers AD site name  (Read 757 times)

Trippinout

  • Newbie
  • *
  • Posts: 8
Get computers AD site name
« on: February 10, 2017, 08:46:39 am »
Anyone have a quick simple script to just get the current AD Site name from a computer.
Script will be run locally on the computer.

Thanks

td

  • Tech Support
  • *****
  • Posts: 2189
    • WinBatch
Re: Get computers AD site name
« Reply #1 on: February 10, 2017, 11:24:35 am »
This longish script illustrates how to obtain the site name for the current domain along with a bunch of other stuff.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/ADSI/Samples~from~Users+Useful~ADSI~Site~server~functions.txt
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


td

  • Tech Support
  • *****
  • Posts: 2189
    • WinBatch
Re: Get computers AD site name
« Reply #2 on: February 10, 2017, 11:54:55 am »
Here's a two liner that may (or may not) get you what you want.

adSys = CreateObject('ADSystemInfo')
strSiteName = adSys.GetDCSiteName('ServerNameHere')
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


Trippinout

  • Newbie
  • *
  • Posts: 8
Re: Get computers AD site name
« Reply #3 on: February 10, 2017, 12:14:22 pm »
Perfect. Thanks..

td

  • Tech Support
  • *****
  • Posts: 2189
    • WinBatch
Re: Get computers AD site name
« Reply #4 on: February 10, 2017, 02:09:53 pm »
A not very elegant  ADSI extender version.

Code: Winbatch
AddExtender("wwads44i.dll")
strServer = 'yourserver'
strServerPath = dsFindPath('LDAP://CN=Sites,CN=Configuration,DC=yoursub,DC=yourdomain', '(&(objectClass=server)(cn=%strServer%))')
strSite = ItemExtract(2, ItemExtract(3, strServerPath, ','), '=')
Pause(strServer:"'s Site", strSite)
 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates