PowerShell Watch Script Command

Here is a simple PowerShell script to get something similar to the watch command on line.  Just put it in your PowerShell modules directory and run “Import-Module Watch”

# Author:       John Rizzo
# Created:      06/12/2014
# Last Updated: 06/12/2014
# Example:      Watch 5 Get-Date

function Watch {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='High')]
    param (
        [Parameter(Mandatory=$False,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [int]$interval = 10,

        [Parameter(Mandatory=$True,
                   ValueFromPipeline=$True,
                   ValueFromPipelineByPropertyName=$True)]
        [string]$command
    )
    process {
        $cmd = [scriptblock]::Create($command);
        While($True) {
            cls;
            Write-Host "Command: " $command;
            $cmd.Invoke();
            sleep $interval;
        }
    }
}

Export-ModuleMember -function Watch
John Rizzo
Director of Technology
Chief Technology Officer with over 17 years experience and expertise in design and delivery of cost-effective, high-performance financial technology solutions. All of these skills have been used to support rapid international growth with budget responsibilities exceeding $25 million annually. Senior Enterprise Architect with extensive hands-on development experience, as well as formal design and architecture background on many successful projects. A seasoned mentor for advanced SDLC practices. Exceptional at team building and motivating either at a peer-to-peer level, or in a leadership role. Excellent communications skills and ability to adapt to diverse environments and cultures effortlessly.

Full software life cycle experience with many industry standard methodologies including Agile development with Scrum and Extreme Programming (XP). Well versed in Test Driven Design (TDD) and Domain Driven Design (DDD). Can adapt to any phase of an existing project from Business
Modeling to Production Support. Technical strengths include OOA/OOD, Ruby, Python, C#, .NET 3.5/4.0, Java, J2EE, Internet Technologies, MSSQL, MySQL and Enterprise Integration.

John Rizzo

Technology, problem solving, learning, business, society and where those things intersect is what I am always thinking about. From my hobbies to my profession I attempt to combine those interests in a way that makes the sum greater than the whole. Find out more about me at linkedin, http://www.linkedin.com/in/johnrizzo1.

You may also like...