Skip to content

Instantly share code, notes, and snippets.

@vexx32
Last active May 22, 2019 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/9f86d20e8026ab337693ce7f2dee9303 to your computer and use it in GitHub Desktop.
Save vexx32/9f86d20e8026ab337693ce7f2dee9303 to your computer and use it in GitHub Desktop.
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