Last active
December 15, 2016 00:05
-
-
Save rodmhgl/13244d254dfa66d9650b218f8b263f75 to your computer and use it in GitHub Desktop.
Why is remoting slower than running over the network?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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