Monitor-BITSTransferStatus.ps1

  • 18 December 2019
  • Sean Huggans
Description: 

Script will report BITS transfer statuses for the local or a remote host every 10 seconds.

Reminder: BITS has a limit of 50 jobs being queued at a time.

Language: 
Powershell
Usage Type: 
Standalone
Script Source: 
#################################################################################################
# Monitor-BITSTransferStatus.ps1
# Author: Sean Huggans
# Version: 19.12.18.1
#################################################################################################
$MachineName = "SomeNameHere"
$MachineName = $env:Computername #Comment this line out to view BITS jobs on a remote host
 
do {
    if ($MachineName.ToUpper() -ne $env:COMPUTERNAME.ToUpper()) {
        if (Test-Connection $MachineName -Count 1 -Quiet) {
 
            Try {
                $Results = Invoke-Command -computername $MachineName -ScriptBlock {
                    $Results = New-object system.collections.arraylist
                    [array]$DownloadJobs = $(Get-BitsTransfer -AllUsers)
 
                    if ($DownloadJobs.count -gt 0) {
                        foreach ($DownloadJob in $DownloadJobs) {
                           $Results.Add("[$(Get-date -format 'HH:mm:ss')]$($DownloadJob.JobID) - $($DownloadJob.JobState) - $([math]::Round($($DownloadJob.BytesTransferred / 1MB),2))MB/$([math]::Round($($DownloadJob.BytesTotal / 1MB),2))MB ($([math]::Round($($DownloadJob.BytesTransferred / $DownloadJob.BytesTotal * 100),2))%)") | out-null
                        }
                    } else {
                        $Results.Add("[$(Get-date -format 'HH:mm:ss')] No BITS transfers in progress.") | out-null
                    }
                    $Results.add("There are $($DownloadJobs.count) total BITS transfers queued.") | out-null
                    return $Results
                }
                cls
                foreach ($Result in $Results) {
                    Write-Host $Result
                }
            } catch {
                Write-Host "$($MachineName) error with PSRemoting."
            }
        } else {
            Write-Host "$($MachineName) is offline."
        }
    } else {
        [array]$DownloadJobs = $(Get-BitsTransfer -AllUsers)
        cls
        if ($DownloadJobs.count -gt 0) {
            foreach ($DownloadJob in $DownloadJobs) {
                Write-host "[$(Get-date -format 'HH:mm:ss')] $($DownloadJob.JobID) - $($DownloadJob.JobState) - $([math]::Round($($DownloadJob.BytesTransferred / 1MB),2))MB/$([math]::Round($($DownloadJob.BytesTotal / 1MB),2))MB ($([math]::Round($($DownloadJob.BytesTransferred / $DownloadJob.BytesTotal * 100),2))%)"
            }
            Write-host "There are $($DownloadJobs.count) total BITS transfers queued."
        } else {
            Write-host "[$(Get-date -format 'HH:mm:ss')] No BITS transfers in progress."
        }
    }
    Start-Sleep -Seconds 10
} until ($null)
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.