Author Topic: Get computers AD site name  (Read 5588 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: 4293
    • 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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 4293
    • 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')
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

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: 4293
    • 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)
 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade