bsharath
asked on
Need a script to update the location of each computer to the location tab
Hi,
I need a script which can update the computers location.
I have this in a text file.
Machinename : Location of the computer
Is there a way to do this.
Need a report to find if it has updated or not.
Regards
Sharath
I need a script which can update the computers location.
I have this in a text file.
Machinename : Location of the computer
Is there a way to do this.
Need a report to find if it has updated or not.
Regards
Sharath
Are you talking about the AD Location attribute? Or a local computer attribute (that I'm not aware of)?
Regards,
Rob.
Regards,
Rob.
ASKER
In AD > Computers > Location...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi RobSampson
In what format should this file be.
ComputerLocations.txt"
In what format should this file be.
ComputerLocations.txt"
As you specified, a text file with:
Machinename:Location
Machinename:Location
For example,
WORKPC1:City1
WORKPC2:City2
Regards,
Rob.
Machinename:Location
Machinename:Location
For example,
WORKPC1:City1
WORKPC2:City2
Regards,
Rob.
ASKER
This works great and you have given me a bonus of even updating the old location as this is soooo useful to me....
Thanks a lot...
Thanks a lot...
ASKER
Can you help with this Q as this would be easy for you.
https://www.experts-exchange.com/questions/22775772/Update-the-System-configuration-to-the-Location-tab-in-computer-objects-in-ADS.html
https://www.experts-exchange.com/questions/22775772/Update-the-System-configuration-to-the-Location-tab-in-computer-objects-in-ADS.html
ASKER
One more help Rob.In this same script can you remove the updating part and just give me a way to output the current status in the computers > location.After updating the location with your script.Later i would want to take a report of what is there when ever i require without updating....
I can raise a new Q if you say ok....
I can raise a new Q if you say ok....
Sorry Sharath, i don't follow with that last bit.....do you want to remove the visible output "while" it is processing, and just leave the "Processed" file as is, or do you want to change the "processed" file?
Regards,
Rob.
Regards,
Rob.
ASKER
I want to fetch only the content in the location tab in all machines in the network.
Now the script updates and even shows the old content.What i want is just to show the content
Like i want to know
Machinename and Location content to a csv file...
Now the script updates and even shows the old content.What i want is just to show the content
Like i want to know
Machinename and Location content to a csv file...
I see. Do you want this to happen from the machines in a text file, or the entire AD?
Rob.
Rob.
ASKER
Machines in the text file...
Oh, well, that's pretty easy, given what we already have. I have modified it just to output the current Location only, without changing anything.
'================
strInputFile = "Computers.txt"
strOutputfile = "ComputerLocations_Current .csv"
If Right(LCase(WScript.FullNa me), 11) = "wscript.exe" Then
Set objShell = CreateObject("WScript.Shel l")
objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
Set objShell = Nothing
WScript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInp utFile, intForReading, False)
Set adoCommand = CreateObject("ADODB.Comman d")
Set adoConnection = CreateObject("ADODB.Connec tion")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio n = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE" )
strDNSDomain = objRootDSE.Get("defaultNam ingContext ")
strBase = "<LDAP://" & strDNSDomain & ">"
strDetails = """Machine Name"",""Current Location"""
While Not objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
strComputer = strLine
'strFilter = "(&(objectCategory=person) (objectCla ss=user))"
strFilter = "(&(objectClass=computer)( cn=" & strComputer & "))"
' Comma delimited list of attribute values to retrieve.
'strAttributes = "sAMAccountName,cn"
strAttributes = "cn,Location"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag e Size") = 100
adoCommand.Properties("Tim eout") = 30
adoCommand.Properties("Cac he Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strComputerName = Replace(adoRecordset.Field s("cn").Va lue, "CN=", "")
WScript.Echo "Processing " & strComputer
strDetails = strDetails & VbCrLf & """" & strComputerName & """,""" & adoRecordset.Fields("Locat ion") & """"
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
Set adoRecordset = Nothing
Wend
adoConnection.Close
Set objOutputFile = objFSO.CreateTextFile(strO utputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo "Done"
MsgBox "Done"
'================
Regards,
Rob.
'================
strInputFile = "Computers.txt"
strOutputfile = "ComputerLocations_Current
If Right(LCase(WScript.FullNa
Set objShell = CreateObject("WScript.Shel
objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
Set objShell = Nothing
WScript.Quit
End If
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInp
Set adoCommand = CreateObject("ADODB.Comman
Set adoConnection = CreateObject("ADODB.Connec
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnectio
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE"
strDNSDomain = objRootDSE.Get("defaultNam
strBase = "<LDAP://" & strDNSDomain & ">"
strDetails = """Machine Name"",""Current Location"""
While Not objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
strComputer = strLine
'strFilter = "(&(objectCategory=person)
strFilter = "(&(objectClass=computer)(
' Comma delimited list of attribute values to retrieve.
'strAttributes = "sAMAccountName,cn"
strAttributes = "cn,Location"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Pag
adoCommand.Properties("Tim
adoCommand.Properties("Cac
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strComputerName = Replace(adoRecordset.Field
WScript.Echo "Processing " & strComputer
strDetails = strDetails & VbCrLf & """" & strComputerName & """,""" & adoRecordset.Fields("Locat
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
Set adoRecordset = Nothing
Wend
adoConnection.Close
Set objOutputFile = objFSO.CreateTextFile(strO
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing
WScript.Echo "Done"
MsgBox "Done"
'================
Regards,
Rob.
ASKER
Thanks a lot this worked.I have raised a new Q for this Answer please put the answer there.I shall close it.
https://www.experts-exchange.com/questions/22781531/Fetch-the-machine-location-details-to-a-csv-file.html
Wanted to give you more points for the excellent job...:)
https://www.experts-exchange.com/questions/22781531/Fetch-the-machine-location-details-to-a-csv-file.html
Wanted to give you more points for the excellent job...:)
I found this site helpful. http://www.computerperformance.co.uk/Logon/CSVDE_LDIFDE.htm