3

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?

1

1 Answer 1

6

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:

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

4
  • That is excellent advice. Is there anyway to call NMAP from a Powershell script to have Powershell initiate the NMAP scan?
    – John
    Jun 19, 2012 at 18:56
  • Good article on how to call executables. stackoverflow.com/questions/1673967/…
    – Mike
    Jun 20, 2012 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, 2012 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, 2012 at 21:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .