[breadcrumb]
You will hopefully have seen my Mass NTFS Compression Tool in the scripts section. From version v1.4 of this script, there is a function to add a status check. The idea behind this is that you can have multiple copies of the Mass NTFS Compression Tool running and use this script to monitor the status of all scripts. There is no limit to the number of scripts you can have running at the time (other than available resources) and this checking tool can be used to monitor remote instances.
I found a large scale use for the Mass NTFS Compression Tool in my job and found that I was running up to 9 instances of the script at a time, passing a CSV file of 25,000 files at a time. As I was running them on a remote machine, I wanted a quick and easy way to monitor the progress of the scripts without having to frequently RDP back to the machine and read the output of 9 scripts.
To use this script, use the -statusNum parameter on the Mass NTFS Compression Tool. Each -statusNum will then generate a log file in Logs\ntfscompress-1.log where 1 is the -statusNum. This script will then read every log file in that location and display an output of how the script is progressing.
Running this script is simple. In the same location as the Mass NTFS Compression Tool, run: .\NTFSCompression-StatusCheck.ps1
If you would like to change the refresh time in seconds (for example, 7 seconds instead of the default 3), you can use the -refresh switch: .\NTFSCompression-StatusCheck.ps1 -refresh 7
Lastly, if you are running the script from a different location to where your log files are stored, you can use the -logs switch to point to a different or network location to find the logs: .\NTFSCompression-StatusCheck.ps1 -logs C:\path\to\logs
The output of the script should look similar to the screenshot below.
Download Mass NTFS Compression Tool – Status Check v1.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
################################################################################################# # # # Mass NTFS Compression Tool - Status Check v1.1 # # # # Written by: Mike Oldfield # # Date: 08/06/2016 # # # # This PS1 reads log files created by the Mass NTFS Compression Tool (NTFSCompression.ps1) # # # # The purpose is to enable an administrator to run multiple instances of the Mass NTFS # # Compression Tool and be able to monitor the progress in one location. # # # # Usage: .\NTFSCompression-StatusCheck.ps1 [-logs C:\path\to\logs] [-refresh 3] # # # # Change Log: # # v1.1: Tidied up script and made some minor improvements such as customisable refresh # # timer # # # ################################################################################################# ############################# # # # PARAMETERS # # # ############################# # Set some avaialble paramters. This bit must come first. param ( [string]$logs = "Logs", # -Logs: Set the path to logs. We assume the "Logs" directory in your current path if nothing specified. [int]$refresh = 3 # -Refresh: Set the refresh timer in seconds. We assume 3 seconds if nothing specified. Refreshing too often (1 second for example) can cause read/write errors, but you may want a longer refresh period (10 seconds for example) ) # Set some variables $scriptVer = "v1.1" # What version of the script is this? Used for header info $scriptAuth = "Mike Oldfield" # Who wrote the script? $scriptLastUpdate = "14/06/2016" # When was the script last updated? ############################# # # # SCRIPTY BIT # # # ############################# # Start a pretty much infinite loop # Hit CTRL+C to kill the script at any time! while ($true) { $okCnt = 0 # Set the overall OK count to 0 $warnCnt = 0 # Set the overall WARN count to 0 $errorCnt = 0 # Set the overall ERROR count to 0 # Go and get all the log files. Sort them in ascending order and just grab the file name $logfiles = Get-ChildItem "$logs" -Force -ErrorAction Stop | sort | select name # Find out what the current time is $time = Get-Date -format F # Clear the PowerShell window. # If we don't, we still see the last instance of the monitor. # That would get messy and confusing Clear-Host # Write a pretty header Write-Host "`r`n ########################################################`r`n" -ForegroundColor darkcyan -NoNewLine Write-Host " ##### " -ForegroundColor darkgray -NoNewLine Write-Host "Mass NTFS Compression Status Check $scriptVer " -ForegroundColor gray -NoNewLine Write-Host "#####`r`n ##### " -ForegroundColor darkgray -NoNewLine Write-Host "Written by: $scriptAuth" -ForegroundColor gray -NoNewLine Write-Host " #####`r`n ##### " -ForegroundColor darkgray -NoNewLine Write-Host "Last Updated: $scriptLastUpdate " -ForegroundColor gray -NoNewLine Write-Host " #####`r`n" -ForegroundColor darkgray -NoNewLine Write-Host " ########################################################`r`n" -ForegroundColor darkcyan # Write the current time, tell us how often we're refreshing and how to quit the script (end the loop) Write-Host " Time: $time`r`n Refreshing every $refresh seconds`r`n`r`n Hit CTRL+C to end this monitoring script!`r`n" # Now, for each file in the logs directory... foreach ($log in $logfiles) { # Get the contents of the log file $content = Get-Content "$logs\$($log.Name)" # Now we want to start splitting the contents apart a bit. # The purpose of this is to make things look pretty on screen $split1 = $content -split "\[" # Split the string wherever you find a [ character $split2 = $split1 -split "\|" # Then split the new string every time we find a | character # Remove some unneccesary text from the status numbers $okNum = $split2[1] -replace "OK:", "" # Find the "OK: xxx" number and remove the "OK:" $warnNum = $split2[2] -replace "WARN:", "" # Find the "WARN: xxx" number and remove the "OK:" $errorNum = $split2[3] -replace "ERROR:", "" # Find the "ERROR: xxx ]" number and remove the "ERROR:" $errorNum2 = $errorNum -replace "]", "" # Finally, remove the ] character from the error number # Now we're left with integers rather than strings, add them all to the overall count $okCnt = $okCnt + $okNum # Add the OK numbers $warnCnt = $warnCnt + $warnNum # Add the WARN numbers $errorCnt = $errorCnt + $errorNum2 # Add the ERROR numbers $overallCnt = $okCnt + $warnCnt + $errorCnt # Add all the numbers together to get an overall tally # Now write a line that should look like below, with some pretty colours: # (1) compress.csv: File xxx of yyy [ OK: xxx | WARN: yyy | ERROR: zzz ]" Write-Host " " $split1[0] "[ " -NoNewLine Write-Host "OK:" -ForegroundColor green -NoNewLine Write-Host $okNum "| " -NoNewLine Write-Host "WARN:" -ForegroundColor yellow -NoNewLine Write-Host $warnNum "| " -NoNewLine Write-Host "ERROR:" -ForegroundColor red -NoNewLine Write-Host $errorNum } # Write a line at the end showing the total numbers for all files. # This should like like below, with some pretty colours: # Totals: OK: vvv | WARN: xxx | ERROR: yyy | OVERALL: zzz Write-Host "`r`n Totals: " -NoNewLine Write-Host "OK: " -ForegroundColor green -NoNewLine Write-Host $okCnt " | " -NoNewLine Write-Host "WARN: " -ForegroundColor yellow -NoNewLine Write-Host $warnCnt " | " -NoNewLine Write-Host "ERROR: " -ForegroundColor red -NoNewLine Write-Host $errorCnt " | " -NoNewLine Write-Host "OVERALL: " -ForegroundColor cyan -NoNewLine Write-Host $overallCnt # Pause the script for however many seconds we told it to refresh by. # Once the sleep is over, it'll loop back to the beginning and repeat for all eternity Sleep $refresh } |