Michael Leonard
asked on
need assistance with a custom script
can someone provide a script that we can use for the following requirement:
check the following file located on 200+ computers:
There will be a value in there for <router_name>
The router name should match the computer name.
Example:
output a report with all systems that do not have a router name that matches the computer name.
thx in advance!
S.
check the following file located on 200+ computers:
C:\ProgramData\Sophos\Remote Management System\3\Router\NetworkReport\ReportData.xml
There will be a value in there for <router_name>
The router name should match the computer name.
Example:
<computer_name>
JSMITHCOMPUTER
</computer_name>
<domain>
SKYNET
</domain>
<router_name>
Router$JSMITHCOMPUTER:72034
</router_name>
output a report with all systems that do not have a router name that matches the computer name.
thx in advance!
S.
Do you have admin shares enabled on these servers? Else accessing the files remotely will be a problem.
ASKER
hi Subsun, I've confirmed the admin shares are enabled, these are primarily workstations. thx
Can you check the following code using the xml file and let me know the results? Of please post a sample xml file (you can remove/replace confidential information).
$Test = [XML](GC C:\ProgramData\Sophos\Remote Management System\3\Router\NetworkReport\ReportData.xml)
$Test.computer_name
$Test.router_name
Here is a sample code. code.. but it's depends on your xml file structure..
GC C:\server.txt | %{
$server = $_
Write-Host "Working with $server"
Try{
#Read xml
$xml = [xml](GC "\\$server\c$\ProgramData\Sophos\Remote Management System\3\Router\NetworkReport\ReportData.xml" -EA Stop)
If ($xml.router_name -match $xml.computer_name){
New-Object PSObject -Property @{
Computer = $server
Match = "Yes"
router_name = $xml.router_name
computer_name = $xml.computer_name
}
}Else{
New-Object PSObject -Property @{
Computer = $server
Match = "No"
router_name = $xml.router_name
computer_name = $xml.computer_name
}
}
}Catch{
New-Object PSObject -Property @{
Computer = $server;Match = "Error"
router_name = "";computer_name = ""
}
}
} | Export-Csv C:\report.csv -nti
ASKER
thanks very much Subsun. I will have time this weekend to obtain a sample XML file and test this script against it.
much appreciated as always!
much appreciated as always!
ASKER
Hi Subsun, initial testing looks excellent. we are going to run in production tomorrow, i'll let you know.
thanks so much. brilliant script.
S.
thanks so much. brilliant script.
S.
ASKER
hi subsun, I've run the script however I'm only seeing "yes" or "error" for each system, we are not see any "no" be generated on a mismatch.
here is one of the XML files
here is one of the XML files
<?xml version='1.0' encoding='UTF-16' ?>
<?xml-stylesheet type='text/xsl' href='transform.xslt' ?>
<RMS_status_report>
<string msg='explanation' />
<sections>
<section name='DNS'>
<string msg='OK' />
</section>
<!-- And another -->
<section name='Certification'>
<string msg='OK' />
</section>
<!-- And another -->
<section name='Incoming'>
<string msg='OK' />
</section>
<!-- And another -->
<section name='Outgoing'>
<string msg='OK' />
</section>
<!-- And another -->
</sections>
<computer_data>
<language>
en_US
</language>
<local_time>
Monday, September 08, 2014 9:20:55 AM
</local_time>
<GMT>
Monday, September 08, 2014 1:20:55 PM
</GMT>
<computer_name>
JSMITH
</computer_name>
<domain>
MYDOMAIN
</domain>
<router_name>
Router$JSMITH:72034
</router_name>
<IOR_port>8192</IOR_port>
<SSLIOP_port>8194</SSLIOP_port>
<parent_addresses>
10.1.1.1,fe80::dd25:df98:ecfd:26c,SYSTEM.MYDOMAIN.COM,SOPHOSSERVER
</parent_addresses>
<actual_parent>
10.1.1.1
</actual_parent>
<router_type>
endpoint
</router_type>
</computer_data>
</RMS_status_report>
ASKER
hi subsun, I just re-verified and the script is generating a "Yes" even for systems that have a mis-match.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are unsure about the xml structure then try replacing line 8 & 9 with following..
$router_name = ($xml.SelectSingleNode("//router_name")).InnerText -replace "\s"
$computer_name = ($xml.SelectSingleNode("//computer_name")).InnerText -replace "\s"
ASKER
brilliant Subsun. thanks much!
You are welcome!..
ASKER
many thanks!
S.