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?
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.Reading it in is easy:
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