Powershell Script | Template (input from pipeline / error handling)

If you want to have a template that delivers some basic functionality just use this as and modify it to your needs.

It needs to have an input but also accepts input from a pipeline (like get-content input.txt | script.ps1).

It offers basic error handling for terminating errors. The variable $ErrorActionPreference = stop makes them all terminating though 🙂


Have fun and let me know if you need any advice.

Check if VM(s) still exist
get-content "list-of-machines.txt" | check if vm exists.ps1
check if vm exists.ps1 vm1
check if vm exists.ps1 vm1, vm2, vm3
One or more Virtual Machine names


    $ErrorActionPreference = "Stop"
    $collection = @()

    try {
        $collection += get-vm $desktop
        write-output "$desktop does exist!"
    catch {
        $collection += "$desktop does not exist!"
    finally {}

    $collection | out-gridview


Leave a Reply

Your email address will not be published.