Not getting output in HTML format

This topic contains 3 replies, has 3 voices, and was last updated by  Sachin Ghagare 2 years, 2 months ago.

  • Author
    Posts
  • #27874

    Sachin Ghagare
    Participant

    Hi All,

    I have created a function to get HTTP return code from specific URL for monitoring purpose however I'm getting desired output in txt format as expected but same results couldn't get via ConvertTo-Html .. (both .txt and html results mentioned below)

    Please advise..! thanks.
    ———————————————–
    Function write-MPConnectivity ()
    {
    $MPConnet = @()
    $MPList = Get-WMIObject -query "select * from SMS_SCI_SysResUse where SiteCode = 'P01' and RoleName = 'SMS Management Point'" -computerName 'SERVERNAME' -namespace "root\sms\site_P01"
    foreach ($MPInformation in $MPList)
    {
    $SSLState = ($MPInformation.Props | where {$_.PropertyName -eq "SslState"}).Value
    $mpname = $MPInformation.NetworkOSPath -replace '\\', "
    if ($SSLState -eq 0)
    {
    $protocol = 'http'
    $port = 80
    }
    else
    {
    $protocol = 'https'
    $port = 443
    }

    $web = New-Object -ComObject msxml2.xmlhttp
    $url = $protocol + '://' + $mpname + ':' + $port + '/sms_mp/.sms_aut?MPLIST'
    try
    {
    $web.open('GET', $url, $false)
    $web.send()

    $HTTPReturn = $web.status
    }
    catch
    {
    $HTTPReturn = "313 – Unable to connect to host"
    $Error.Clear()
    }
    if ($HTTPReturn -eq 200) {$Stat = 'OK'} else {$Stat = 'Failed'}
    $MPchk = New-Object psobject
    Add-Member -InputObject $MPchk -MemberType NoteProperty -Name ServerName -Value $mpname
    Add-Member -InputObject $MPchk -MemberType NoteProperty -Name HTTPReturnCode -Value $HTTPReturn
    Add-Member -InputObject $MPchk -MemberType NoteProperty -Name Status -Value $Stat
    $MPConnet += $MPchk

    }

    return, $MPConnet

    }
    # write-MPConnectivity | out-file -FilePath 'c:\temp\cm12.txt'
    write-MPConnectivity | ConvertTo-Html | Set-Content c:\temp\test.htm

    ————————————————

    Output in txt :

    ServerName HTTPReturnCode Status
    ———- ————– ——
    SERVER.DOMAIN 200 OK
    SERVER.DOMAIN 200 OK
    SERVER.DOMAIN 200 OK
    SERVER.DOMAIN 200 OK

    html output:

    Count Length LongLength Rank SyncRoot IsReadOnly IsFixedSize IsSynchronized
    4 4 4 1 System.Object[] FALSE TRUE FALSE

  • #27875

    Tim Pringle
    Participant

    Hey Sachin. Is the comma intentional in your return statement?

  • #27884

    kvprasoon
    Participant

    Hi Sachin,
    The Problem is nothing , But the 'comma' after return as Tim Said,
    Regards.,
    kvprasoon

  • #27887

    Sachin Ghagare
    Participant

    You got it right Tim & kvprasoon ..!

    Thank you very much.. 🙂

You must be logged in to reply to this topic.