Core/ServerRake.Core.Utility.ps1
|
################# ### UTILITY ### ################# function Send-RemoteScript { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string[]] $ComputerName, [Parameter(Mandatory = $true)] [scriptblock] $RemoteScript, [Parameter(Mandatory = $false)] $ArgumentList ) if (!$secret -AND !$secretPlain) { throw "No secret sessions are currently opened. Start a session with 'Open-SecretSession' and try again." } if ($jh) { Write-Host "Running command from jumphost." -ForegroundColor Yellow $payload = Invoke-Command -Session $jh -ArgumentList $ComputerName, $RemoteScript, $argumentList, $secretPlain -ScriptBlock { param ($ComputerName, $RemoteScript, $argumentList, $secretPlain) $responses = @() $RemoteScript = [scriptblock]::Create($RemoteScript) $responses += Invoke-Command -ComputerName $ComputerName -ScriptBlock $RemoteScript -ArgumentList $argumentList -Credential $secretPlain return $responses } return $payload } else { $responses = @() $responses += Invoke-Command -ComputerName $ComputerName -ScriptBlock $RemoteScript -ArgumentList $argumentList -Credential $secretPlain return $responses } } |