Occasionally I need to run a commands in PowerShell 7 on a system, but I don’t want to expose secrets or run certain logic on the machine. Using Invoke-ImmyCommand, we can use a pwsh script block to run commands in PowerShell 7 directly on the machine. We can return data from those blocks. However, I can’t find a way to pass variables into the pwsh script block. Being able to run something like this would be really helpful:
$Test = "Test"
Invoke-ImmyCommand -ScriptType pwsh {
$using:Test
return "Passing $Test back from pwsh"
}