Recently, I had to list and dump the sites information from AD. So, I created this script for it:
on error resume next
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")
intCtr = 0
For Each objSite In objSitesContainer
intStart = Instr(objSite.description,"(")
intEnd = Instr(objSite.description,")")
'Wscript.echo objSite.description
strSiteCode = Mid(objSite.description,intStart)
intStart = Instr(objSite.description,":")
intEnd = Instr(objSite.description,",")
strBusiness = Mid(objSite.description,intStart+1, intEnd-intStart-1)
intStart = InstrRev(objSite.description,"/")
intEnd = InstrRev(objSite.description,":")
strLocation = Mid(objSite.description,intStart+1, intEnd-intStart-1)
intStart = Instr(objSite.description,"/")
intEnd = InstrRev(objSite.description,"/")
strCountry = Mid(objSite.description,intStart+1, intEnd-intStart-1)
WScript.Echo strSiteCode & "-" & strLocation & ";" & objSite.cn & ";" & strCountry & ";" & strBusiness
intCtr = intCtr + 1
'If intcTR = 15 Then Exit For
Next
You need to run in on a DC.
on error resume next
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.Filter = Array("site")
intCtr = 0
For Each objSite In objSitesContainer
intStart = Instr(objSite.description,"(")
intEnd = Instr(objSite.description,")")
'Wscript.echo objSite.description
strSiteCode = Mid(objSite.description,intStart)
intStart = Instr(objSite.description,":")
intEnd = Instr(objSite.description,",")
strBusiness = Mid(objSite.description,intStart+1, intEnd-intStart-1)
intStart = InstrRev(objSite.description,"/")
intEnd = InstrRev(objSite.description,":")
strLocation = Mid(objSite.description,intStart+1, intEnd-intStart-1)
intStart = Instr(objSite.description,"/")
intEnd = InstrRev(objSite.description,"/")
strCountry = Mid(objSite.description,intStart+1, intEnd-intStart-1)
WScript.Echo strSiteCode & "-" & strLocation & ";" & objSite.cn & ";" & strCountry & ";" & strBusiness
intCtr = intCtr + 1
'If intcTR = 15 Then Exit For
Next
You need to run in on a DC.
No comments:
Post a Comment