none
Powershell Script with HTML Output RRS feed

  • Question

  • Hi,

    I ran this command and want to add html tags so that I can enhance my output . Can you please suggest.

    $test = @('abcy.com:443')

    Foreach ($t in $test)
    {
      $source = $t.Split(':')[0]
      $port = $t.Split(':')[1]
     
      Write-Host "Connecting to $source on port $port"

      try
      {
        $socket = New-Object System.Net.Sockets.TcpClient($source, $port)
       Write-Host "Connected`n"-ForegroundColor Green
      }
      catch [Exception]
      {
        Write-Host $_.Exception.GetType().FullName
        Write-Host $_.Exception.Message
        Write-Warning "The connection failed"  
      }

      }

    Please suggest me what all html tags can be added, how to add the output in different lines, add a background color, a table where the port , status is shown. Please help me with the same.

    Thursday, July 14, 2016 12:09 AM

Answers

All replies

  • Hi,

    Please help me in adding html tags so that I get better and enhanced output please.

    Thursday, July 14, 2016 12:15 AM
  • Also, please tell me how I can add date & time when I receive this report
    Thursday, July 14, 2016 12:20 AM
  • You cannot use HTML in PowerShell. You can use ConvertTo-Html to create a file with HTML.

    help convertto-html -full


    \_(ツ)_/

    Thursday, July 14, 2016 12:32 AM
    Moderator
  • Thursday, July 14, 2016 12:34 AM
    Moderator
  • Hi,

    Thank you for replying, is there any way we can automate the script I wrote above and can schedule it because while running on the powershell I get output on the screen. I want the output on the text file where it gives me status of all the url's where it is connected or failed.

    Please guide.

    Thursday, July 14, 2016 12:47 AM
  • I recommend learning a bit  of PowerShell.  In a short time you will be able to do this.  We won't write you script for you.

    Start with these tutorials. They will show you how in a very short time. https://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    \_(ツ)_/

    Thursday, July 14, 2016 12:53 AM
    Moderator
  • This is the script which you have created and I have modified , but the issue is on the powershell when I run it I get the output there only on the screen I need it in a separate file where I can get port and status  and can automate the same.

    $test = @("url's")

    Foreach ($t in $test)
    {
     
      Write-Host "Connecting to $source on port $port" 

      try
      {
        $socket = New-Object System.Net.Sockets.TcpClient($source, $port)
       Write-Host "Connected`n"-ForegroundColor Green 
      }
      catch [Exception]
      {
        Write-Host $_.Exception.GetType().FullName  
        Write-Host $_.Exception.Message  
        Write-Host "$Connection Failed"   
      }
      }

    Please run this in powershell and it will give output on the same screen. Please guide me as I need the output with status along with port in a separate file so that I can schedule it.

    Thanks in Advance

    Thursday, July 14, 2016 12:58 AM
  • Hi,No I just want you to guide the script is there its redy but the issue is I am getting output there only on the powershell screen I need the output in a separate file

    Thursday, July 14, 2016 1:03 AM
  • Change write-Host to Out-File

    help out-file -full


    \_(ツ)_/

    Thursday, July 14, 2016 1:04 AM
    Moderator
  • Hi,No I just want you to guide the script is there its redy but the issue is I am getting output there only on the powershell screen I need the output in a separate file

    Please take the time to learn basic PowerShell. We do not write custom scripts and we do not fix scripts you have found.


    \_(ツ)_/

    Thursday, July 14, 2016 1:05 AM
    Moderator