Wait-RemoteComputerShutdown.ps1


Description

Purpose

Monitors remote computers and reports when each has shut down (stops responding to ping).

Detailed Description

Accepts computer names via pipeline or array. Pings each computer until it stops responding, then reports shutdown.

Back to Top

Usage

Example 1

'PC1','PC2','PC3' | Wait-RemoteComputerShutdown
Get-ADComputer -Filter * Select-Object -ExpandProperty Name Wait-RemoteComputerShutdown

Back to Top

Notes

Requires network connectivity and appropriate permissions.

Back to Top


Script

function Wait-RemoteComputerShutdown {
    <#
    .SYNOPSIS
    Monitors remote computers and reports when each has shut down (stops responding to ping).

    .DESCRIPTION
    Accepts computer names via pipeline or array. Pings each computer until it stops responding, then reports shutdown.

    .PARAMETER Name
    The name(s) of the remote computer(s) to monitor. Accepts pipeline input.

    .EXAMPLE
    'PC1','PC2','PC3' | Wait-RemoteComputerShutdown
    Get-ADComputer -Filter * | Select-Object -ExpandProperty Name | Wait-RemoteComputerShutdown

    .NOTES
    Requires network connectivity and appropriate permissions.
    #>
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory, Position=0)]
        [Alias('ComputerName')]
        [string[]]$Name
    )

    process {
        foreach ($computer in $Name) {
            Write-Host "Monitoring $computer for shutdown..."
            while (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
                Write-Host "$computer is still online..."
                Start-Sleep -Seconds 2
            }
            Write-Host "$computer has shut down (no longer responding to ping)."
        }
    }
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top