-
-
Save vexx32/9f86d20e8026ab337693ce7f2dee9303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-SomeTask { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[ValidateNotNullOrEmpty()] | |
[string[]] | |
$ComputerName | |
) | |
begin {} | |
process { | |
foreach ($Computer in $ComputerName) { | |
try { | |
if (Test-Connection $Computer -Quiet) { | |
# Do some task | |
} | |
else { | |
throw "$Computer is not reachable; the task was not performed." | |
} | |
} | |
catch { | |
Write-Error $_ | |
} | |
} | |
} | |
end {} | |
} | |
Invoke-SomeTask -ComputerName 'TestSystem1', 'TestSystem2' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment