How do I filter the output of raw XML data?

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Jonathan Warnken Jonathan Warnken 2 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #46032
    Profile photo of Kiran
    Kiran
    Participant

    I want to print out only specific meta data about the files and folders in a remote folder that is accessible via REST commands. I am using this code:

    $test = Invoke-WebRequest -Uri "http://acme777.com"
    echo $test.content
    #acme777.com is a Rest URL (semi-website) with a directory of files and other subdirectories

    The above two lines of PowerShell code print raw XML data. This data is metadata about the folder found when you browse to http://acme777.com.

    How do I make the output print four exclusive types of items? I want to print a list of every file in the directory. So the four things are file name, file size, the user account who created the file (or the name of the file creator), and the time the file was last modified.

    Since the current two lines print out data like this:

    ...
    changeTimeString"2016-06-06T12:00:00-0400"
    owner=""
    domain=""
    ...

    how do I select the content (or the entire line unformatted) for the four traits of metadata I mentioned?

    A helpful response to this post would include generic info about how to do it (e.g., "find the four lines you want returned and use the field descriptor to the left of the equals sign"). I found that piping my two lines of PowerShell code to a "select-string" clause does not help. If a pattern match is found, all the content is returned. Otherwise nothing is returned.

    One way around my problem is to redirect the output to a file. I then modify this file and use individual lines separately with the select-string option. I'd rather not use this because of the excessive I/O to the disk.

    My main question is, how do I print out only specific XML elements of each file that is listed and returned with my two lines of PowerShell code at the top. A second question is, what is the owner? The account that created the file?

    #46036
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    Your question is really close to the October 2015 Scripting games challenge. Take a look at the official answer and the submissions

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.