Wrap this in a function (script block).
<pre lang="PowerShell">
$block = { ... your custom method ... }
Then put the function call in a loop that runs on a list of servers as shown here:
foreach ($Server in $Servers) {
if (Test-Connection -ComputerName $Server -Quiet -Count 1) {
Invoke-Command -ComputerName $Server -ScriptBlock { $block }
}
else {
Write-Host "$Server appears to be offline!"
}
}