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: Reset Active Directory Server

Step 0: # Ensure that AD management module is available for PS Sessionif (!(get-module -name…

PowerShell: Set PasswordNeverExpires on SamAccountName

Quick 1-liner Code $accounts=@( 'orange', 'apple', 'pear', 'dog', 'cat', 'dinosaur', 'chicken', 'cow', 'yomama', 'yodada' )…

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…