Link to home
Start Free TrialLog in
Avatar of Tahir Qureshi
Tahir QureshiFlag for Australia

asked on

Script Extension require update AD computer location base on sites subnet

I had this question after viewing Need a script to update the location of each computer to the location tab.


I am not a programmer. I would like someone modification to the above script so that it can meet my requirement
Instead of taking value(computerName, location) from a csv file. I would like to take location value from VLan (because each site has a specific VLan) and display the site name in AD location attribute so that I don't need to update csv file again and again.

Yes I would like to save the output file into csv at a specific location but I don't want any notification if script has exit code = 0.    

lastly each computer should have only one entry in csv file. For example If someone login to the computer at New York than Dallas. the csv file should contain only one entry for Dallas (there should be no entry for New York)

once script is ready I will setup as a login script so that It will update automatically
Avatar of yo_bee
yo_bee
Flag of United States of America image

You reference that you want to us VLAN as the value to use to segregate between the locations.
Is this going to be dynamic or leverage the column and if the computer object is in Vlan1 the Location field will be populated with NYC?
does your CSV have the computer name as a column?

Do you have a copy of your CSV?

This is a basic idea that you can follow
#imports the module for you to manage AD
Import-Module ActiveDirectory

#Imports the content from a CSV.
$List = Import-Csv -Path "C:\Users\xxxxx\ADUSERS.CSV"

#This will go through each record and use SamAccountName column from the CSV file
ForEach ($member in $list)
{
#CN is the computerName 
#location is location
Set-ADComputer -Identity $member.cn -Location $member.location

}

Open in new window

Avatar of Tahir Qureshi

ASKER

I don't want to give value to script. it should be automatically. I want to use this script as a login script
I can get the the site through my script. i just want to store this value to location attribute

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
 
strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC
 
Set objSubnetsContainer = GetObject(strSubnetsContainer)
 
objSubnetsContainer.Filter = Array("subnet")
 
Set objHash = CreateObject("Scripting.Dictionary")
 
For Each objSubnet In objSubnetsContainer
    objSubnet.GetInfoEx Array("siteObject"), 0
    strSiteObjectDN = objSubnet.Get("siteObject")
    strSiteObjectName = Split(Split(strSiteObjectDN, ",")(0), "=")(1)
 
    If objHash.Exists(strSiteObjectName) Then
        objHash(strSiteObjectName) = objHash(strSiteObjectName) & "," & _
            Split(objSubnet.Name, "=")(1)
    Else
        objHash.Add strSiteObjectName, Split(objSubnet.Name, "=")(1)
    End If
Next

For Each strKey In objHash.Keys
    WScript.Echo strKey & "," & objHash(strKey)
Next

Open in new window

Where are you getting the Vlan tag from?
I am not aware of any value within WMI or ipconfig that the Vlan is stored. Are

I would assume you have each Vlan on a 24 bit subnet and each one of your vlans ipaddress will have a different third octet. Is that correct?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great

Thanks Rob