Harvesting specific contents from Web Page

Welcome Forums General PowerShell Q&A Harvesting specific contents from Web Page

This topic contains 2 replies, has 3 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #63940

    Topics: 13
    Replies: 11
    Points: 32
    Rank: Member


    I'm newbie to Powershell.

    As part of routine health check, i need to monitor several web application servers manually using URL for each server. just wondering if I could get status of all web server components in single file (html/txt/csv) would make my job easy.

    to start, I used 'Invoke-webrequest' followed by RawContent where I see expected output (ex. Cognos-ContentManager-State: running in below expample) but with more un-necessary information.
    so how do I get specific contents from each URL...

    I'm expecting output something like,
    URL Component Status
    url1 Running
    url2 Running
    url3 Standby

     PS C:\WINDOWS\system32> $webpage=Invoke-webrequest "http://myserver:9300/p2pd/servlet"

    HTTP/1.1 200 OK 
    X-Cognos-ContentManager-State: running
    Content-Length: 712 
    Content-Type: text/html 
    Date: Fri, 10 Feb 2017 14:28:10 GMT 
    Server: Apache-Coyote/1.1 

  • #63946

    Topics: 2
    Replies: 525
    Points: 24
    Team Member
    Rank: Member

    Please check if below works for you:

    $uriList = @(
    foreach ($uri in $uriList) {
        $response = Invoke-WebRequest -Uri $uri -UseBasicParsing
        if ($response.RawContent -match 'X-Cognos-ContentManager-State: (.+)') {
            [PSCustomObject] @{
                URL= $uri
                ComponentStatus = $Matches[1]
  • #63949

    Topics: 3
    Replies: 262
    Points: 68
    Helping Hand
    Rank: Member

    That looks like header info.

    $uri = @('one.com','two.com')
    foreach ($u in $uri){
        $test = Invoke-WebRequest -Uri $u
            URL = $u
            Status = $test.Headers['X-Cognos-ContentManager-State']

The topic ‘Harvesting specific contents from Web Page’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort