# This is a working example of hoping without delegation. Fresh creds can be passed in a nested -ScriptBlock
$hop1="SERVER01"
$hop2="SERVER02"
$domainAdmin="someAdmin"
$cred = Get-Credential "$env:USERDOMAIN`\$domainAdmin"
Invoke-Command -ComputerName $hop1 -Credential $cred -ScriptBlock{
param($hop2,$cred)
"Currently at hop: $ENV:computername.";
Invoke-Command -ComputerName $hop2 -Credential $Using:cred -ScriptBlock {
"Reached hop: $ENV:computername.";
}
} -Args $hop2,$cred
Categories: