Posted On October 1, 2019

PowerShell: How To Bypass Double Hop Problems

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: How To Bypass Double Hop Problems
# 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Gather Information About Windows Shutdown Reasons

Copy and Paste this to See Result(s): $computername=$env:computername $limitEventsCount=40000 $daysSearchLimit=30 function getWindowsShutdownReason{ param( $computername=$env:computername, $limitEventsCount=10000,…

PowerShell: Get All Hyper-V Servers in the Domain or Forest

This is a working version to correct my previous codes posted somewhere on this site…

Linux: Using Bash to Search for Files Matching Certain Extensions

# using tree: list any files in a directory parentDirectory=/home tree --prune $parentDirectory # using…