Implicit Remote PowerShell usage - scriptblock

I am trying to use implicit delete . We have a jump server in another data center. I want to use Invoke-Command

implicitly on this jump server so that I can run commands on other servers that it can access. I can export Invoke-Command

and import a prefixed module. The problem I am running into is that it says it cannot convert the string to a script block.

Here's an example:

Invoke-xxxCommand -ComputerName 'whatever-server' -ScriptBlock {
    Write-Host $env:COMPUTERNAME
}

      

I understand that I can just use PSSession to connect to the transition server. I'm curious as to why this doesn't work.

Here is the error:

Unable to bind ScriptBlock parameter. Unable to convert value "Write-Host $ env: COMPUTERNAME" of type "System.String" to enter "System.Management.Automation.ScriptBlock".

+3


source to share





All Articles