Windows Vista Forums

tutorial on working with xml files in powershell?
  1. #1


    Jim Lancaster Guest

    tutorial on working with xml files in powershell?

    I'm trying to write a series of scripts to run discovery on a prospect or new
    client's network. I'm familiar enough with WMI and Powershell to get
    whatever data I want from a computer once I connect to it. But before that I
    need to (1) discover the active NIC on my laptop (wireless? ethernet?) and
    learn the network number (e.g., 192.168.1.0/24), then (2) scan the network to
    find the active devices using something like NMAP, noting which devices are
    Windows hosts, and finally (3) scan each Windows host and gather the hardware
    and software inventory and store it to an XML file.

    Right now I'm stuck handing off the data from step (2) to (3). I've got an
    XML file that contains the active hosts. I just need to know how to read it.
    Any help would be greatly appreciated.

    The XML file looks like this. (I'm only interested in "status state='up'" ) :
    <?xml version="1.0" ?>
    <?xml-stylesheet href="nmap.xsl" type="text/xsl"?>
    <!-- Nmap 4.21ALPHA4 scan initiated Thu Apr 19 23:42:31 2007 as: nmap -sP -R
    -oX c:\myscan.xml 192.168.1.0/24 -->
    <nmaprun scanner="nmap" args="nmap -sP -R -oX c:\myscan.xml 192.168.1.0/24"
    start="1177044151" startstr="Thu Apr 19 23:42:31 2007" version="4.21ALPHA4"
    xmloutputversion="1.01">
    <verbose level="0" />
    <debugging level="0" />
    <host>
    <status state="down" />
    <address addr="192.168.1.0" addrtype="ipv4" />
    </host>
    <host><status state="up" />
    <address addr="192.168.1.1" addrtype="ipv4" />
    <address addr="00:13:10:34:29:37" addrtype="mac" vendor="Cisco-Linksys" />
    <hostnames />
    </host>
    <host><status state="up" />
    <address addr="192.168.1.2" addrtype="ipv4" />
    <address addr="00:B00:61:3BB" addrtype="mac" vendor="Dell Computer" />
    <hostnames><hostname name="sbs2003.lancaster.local" type="PTR"
    /></hostnames>
    </host>




      My System SpecsSystem Spec

  2. #2


    klumsy@xtra.co.nz Guest

    Re: tutorial on working with xml files in powershell?

    $a = [xml](get-content myfile.xml)

    that will create a Xmldocument object.. you can then interact with
    that..
    powershell analyzer has great support for XML as per this screenshot
    http://www.powershellanalyzer.com/im...vidscreen4.png

    i've used powershell extensively personal with XML dealing with files
    that had millions of lines of XML successfully. Powershell really
    helped dicern the trees from the forest for those projects.


      My System SpecsSystem Spec

tutorial on working with xml files in powershell? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
PowerShell impersonation (in C#) - not working downatone PowerShell 1 25 Mar 2009
powershell -sta not working Doug PowerShell 3 02 Jun 2008
Working with PublicFolders in PowerShell Bill Hobson PowerShell 8 08 Nov 2007
Powershell scripts not working with Vista powershell Ben PowerShell 20 10 Oct 2007
Working links for PowerShell 1.0 RTW Andrew Watt [MVP] PowerShell 4 14 Nov 2006