• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

Files Version Check Using Powershell | Ping-Test | HTML report

Files Scan Using Powershell | HTML Report, When there is a requirement to check a file or folder status on a single machine it is easy as you simply log into that machine and you can check it, imagine when there are many servers and desktops that you need to search a file or validate a file then it takes much time or even days to check on all the servers.

Here is the  PowerShell script that tests the files or folders (I have taken two file paths however you can declare more as per your need) availability on the remote computers and generates a clear HTML report for auditing, this really useful when you are installing code or when there is a need  to validate the missing files or folders on the servers for an unknown reason.

Before you run the script

we need to create a text file as serverlist.txt, in my script I have created it in C:\serverlist.txt drive, however you can create it in any location and change path in the script $ServerList = Get-Content “c:\serverList.txt”  and the output file I have set the path as $OutputFile = “c:\Output.htm” this can change this path too, basically it generates an HTML file when the script finishes the scan.

Here is the sample output:

If you want to change the HTML report style or width of the table, yes, it is possible, you can simply locate the “width:45%”  and change it as per your need and this is also same for color code as well.

Script Code

$OutputFile = "c:\Output.htm"
$ServerList = Get-Content "c:\serverList.txt"
$Result = @()
Foreach($ServerName in $ServerList)
{
        $pingStatus = Test-Connection -ComputerName $servername -Count 1 -Quiet
        if($pingstatus -eq 'true')
        {$ping='Online'}
        Else
        {$ping='Offline'}
        # Here we need declare the files or folders you want to test as wether they are available on the remote machines
        # File path one techieseek.com
        $default = Test-Path -path "\\$ServerName\c$\users\default"
        #File path two, you can have more files for testing, all you need to declare it.
        $public = Test-Path -path "\\$ServerName\c$\users\public"
        $ser =$null
        if (($default -and $public) -ne $true)
        {
        $ser = " FOlders are missing on " + $ServerName }
            if($ser -ne $null){
            $Result += New-Object PSObject -Property @{
            ServerName = $ServerName
            Description = "Server Status"
            Status = $Ping
            FolderCheck = $ser
        }
            }
        }
            if($Result -ne $null)
            {
            $HTML = '<style type="text/css">
            #Header{font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;width:45%;border-collapse:collapse;}
            #Header td, #Header th {font-size:14px;border:1px solid #98bf21;padding:3px 7px 2px 7px;}
            #Header th {font-size:14px;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#fff;}
            #Header tr.alt td {color:#000;background-color:#EAF2D3;}
            </Style>'
            $HTML += "<HTML><BODY><Table border=1 cellpadding=0 cellspacing=0 id=Header>
            <TR>
            <h2>FilesScan Script</h2>
            <TH><B>Server Name</B></TH>
            <TH><B>Description</B></TH>
            <TH><B>Status</B></TH>
            <TH><B>FolderCheck</B></TH>
            </TR>"
        Foreach($Entry in $Result)
        {
        if($Entry.Status -ne "Online")
        {
        $HTML += "<TR bgColor=Red>"
        }
        else
        {
        $HTML += "<TR>"
        }
$HTML += "
    <TD>$($Entry.ServerName)</TD>
    <TD>$($Entry.Description)</TD>
    <TD>$($Entry.Status)</TD>
    <TD>$($Entry.FileScan)</TD>
    </TR>"
}
$HTML += "</Table></BODY></HTML>"
$HTML | Out-File $OutputFile -Force
}

#Thank you File path one techieseek.com

Conclusion:

This above script validates the Remote machines or desktop status first and then it scans the file’s path that you have provided in the script, it creates the HTML format report when the server, desktop machine, and files are not available on any server or desktop machine, it doesn’t write anything when the file is not missing..

Thank you for reading this article, if you have any questions please let us know.

Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com