locked
Script to modify the location attribute in an existing subnet registered on AD sites RRS feed

  • Question

  • Could anyone help me to make an script to modify the location attribute in an existing subnet registered on AD sites and services.
    Using the script to create subnet, like this one below, occurs error because the subnet already exist:

     Set objRootDSE = GetObject("LDAP://RootDSE")
      strConfigurationNC = objRootDSE.Get("configurationNamingContext")

      strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
      strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

      '-- Create Subnet --
      Set objSubnetsContainer = GetObject(strSubnetsContainer)

      Set objSubnet = objSubnetsContainer.***MODIFY/UPDATE***("subnet", strSubnetRDN)

      objSubnet.Put "siteObject", strSiteObjectDN
      objSubnet.Put "description", strDescription
      objSubnet.Put "location", strLocation
      objSubnet.SetInfo

    Thanks,

    Tuesday, September 9, 2014 8:20 PM

Answers

  • Just get the subnet by name:

    subnet = "192.168.1.0\/24"
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strConfigurationNC = objRootDSE.Get("configurationNamingContext")
    
    strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
    strSubnet = "LDAP://CN=" & subnet & ",cn=Subnets,cn=Sites," & strConfigurationNC
    
    Set objSubnet = GetObject(strSubnet)
    
    objSubnet.Put "description", strDescription
    objSubnet.Put "location", strLocation
    objSubnet.SetInfo


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Wednesday, September 10, 2014 7:36 PM
    • Marked as answer by Bill_Stewart Monday, October 20, 2014 5:31 PM
    Tuesday, September 9, 2014 8:40 PM

All replies

  • Just get the subnet by name:

    subnet = "192.168.1.0\/24"
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strConfigurationNC = objRootDSE.Get("configurationNamingContext")
    
    strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC
    strSubnet = "LDAP://CN=" & subnet & ",cn=Subnets,cn=Sites," & strConfigurationNC
    
    Set objSubnet = GetObject(strSubnet)
    
    objSubnet.Put "description", strDescription
    objSubnet.Put "location", strLocation
    objSubnet.SetInfo


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Wednesday, September 10, 2014 7:36 PM
    • Marked as answer by Bill_Stewart Monday, October 20, 2014 5:31 PM
    Tuesday, September 9, 2014 8:40 PM
  • Thanks a lot,  it works.

    Lakoroll

    Wednesday, September 10, 2014 7:24 PM
  • Thanks a lot,  it works.

    Lakoroll

    Just remember that we always get things by their aDSPath or the path. aDSPath is "LDAP://" plus the DN.


    ¯\_(ツ)_/¯

    Wednesday, September 10, 2014 7:51 PM