Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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:
C:\ProgramData\Sophos\Remote Management System\3\Router\NetworkReport\ReportData.xml

Open in new window


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>

Open in new window



output a report with all systems that do not have a router name that matches the computer name.

thx in advance!

S.
0
siber1
Asked:
siber1
  • 7
  • 6
1 Solution
 
siber1Author Commented:
can anyone provide assistance with this?

many thanks!

S.
0
 
SubsunCommented:
Do you have admin shares enabled on these servers?  Else accessing the files remotely will be a problem.
0
 
siber1Author Commented:
hi Subsun, I've confirmed the admin shares are enabled, these are primarily workstations.   thx
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
SubsunCommented:
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

Open in new window

0
 
SubsunCommented:
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

Open in new window

0
 
siber1Author Commented:
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!
0
 
siber1Author Commented:
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.
0
 
siber1Author Commented:
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

<?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>

Open in new window

0
 
siber1Author Commented:
hi subsun, I just re-verified and the script is generating a "Yes" even for systems that have a mis-match.
0
 
SubsunCommented:
The xml structure is different.. Can you confirm the xml format is same as you posted in all computers?
If yes test with following code..
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)
 
 $router_name = $Xml.RMS_status_report.Computer_data.Router_name -replace "\s"
 $computer_name = $Xml.RMS_status_report.Computer_data.Computer_name -replace "\s"

	If ($router_name -match $computer_name){
		New-Object PSObject -Property @{
		Computer = $server
		Match = "Yes"
		router_name = $router_name
		computer_name = $computer_name
		}
	}Else{
		New-Object PSObject -Property @{
		Computer = $server
		Match = "No"
		router_name = $router_name
		computer_name = $computer_name
		}
	 }
	}Catch{
		New-Object PSObject -Property @{
		Computer = $server;Match = "Error"
		router_name = "";computer_name = ""
		}
	}
} | Export-Csv C:\report.csv -nti

Open in new window

0
 
SubsunCommented:
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"

Open in new window

0
 
siber1Author Commented:
brilliant Subsun. thanks much!
0
 
SubsunCommented:
You are welcome!..
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now