Skip to content

Instantly share code, notes, and snippets.

@rodmhgl
Last active December 15, 2016 00:05
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 rodmhgl/13244d254dfa66d9650b218f8b263f75 to your computer and use it in GitHub Desktop.
Save rodmhgl/13244d254dfa66d9650b218f8b263f75 to your computer and use it in GitHub Desktop.
Why is remoting slower than running over the network?
# Remote Code
$SB = {
param($file)
$SHA1 = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$stream = [System.io.file]::Open($file, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
$hash = [System.BitConverter]::ToString($SHA1.ComputeHash($stream))
$hash = $hash.replace('-','')
$hash = "0x$hash"
$stream.Close()
return $hash
}
if (-not(Get-PSSession -ComputerName $ComputerName)) {
$CurrentSession = New-PSSession -ComputerName $ComputerName
} else {
$CurrentSession = Get-PSSession -ComputerName $ComputerName
}
$hash = Invoke-Command -Session $CurrentSession -ScriptBlock $SB -ArgumentList $file
# End Remote Code
# Local Code
$SHA1 = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider
$stream = [System.io.file]::Open($file, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
$hash = [System.BitConverter]::ToString($SHA1.ComputeHash($stream))
$hash = $hash.replace('-','')
$hash = "0x$hash"
$stream.Close()
# End Local Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment