Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am working on a project where I would like to perform host documentation for a variety of items. Part of these items would be sourced from Powershell and the rest would be sourced from NMAP. For the Powershell part, I am working on trying to build something homegrown and similar to the SYDI-Server project. Instead of WMI it would use Powershell and allow for a much larger and easier method in which to obtain various results from remote machines. Also, the SYDI-Server project has not been updated in a while. The NMAP piece would be used to perform a scan or two on the remote host and return the results such that Powershell could use or consume those and add them to the final report being generated. The idea is similar for the reporting to be a MS Word document that is output from Powershell that contains all of the elements needed for the host documentation.

All of that said, is there a way to have data shared or sent back and forth from Powershell to NMAP? Is there a way to have the results from NMAP used or parsed in Powershell for further manipulation?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

NMAP results can be read into powershell rather easily. NMap has an option to output results in XML format. This is controlled by the -oX option. PowerShell likes XML.

nmap [options] -oX results.xml [targets]

Reading it in is easy:

[xml]$NmapResults = Get-Content results.xml

Which will create a data-structure in $NmapResults that you can move around in to get at what you want.

For how to access individual XML elements, I go into that in a different ServerFault answer:

http://serverfault.com/a/154094/3038

share|improve this answer
    
That is excellent advice. Is there anyway to call NMAP from a Powershell script to have Powershell initiate the NMAP scan? –  John Jun 19 '12 at 18:56
    
Good article on how to call executables. stackoverflow.com/questions/1673967/… –  Mike Jun 20 '12 at 11:50
    
Is there a way to have the XML file stored temporarily in memory or into an array for PowerShell to use without having to actually write the file to disk first? –  John Jun 21 '12 at 16:37
    
@John That's an NMAP problem, not powershell, and it doesn't appear to output XML to stdout in any way. –  sysadmin1138 Jun 21 '12 at 21:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.