0

I have variable in variable group and I try to use them in Invoke-Command -ScriptBlock.

And is not found the variable, not success to reach to variables in variable group.

The script run in PowerShell, in release:

Invoke-Command -ComputerName X -ScriptBlock {
Write-Host $env:Mypod
}

I read about argument list, but I don't know how to use it.

2
  • not work , in the computer we login to hem to do the script is not recognize the variables from variable group Commented Mar 30, 2022 at 11:12
  • 1
    This is the usual way of passing an argument to Invoke-Command. $var1 = $env:Mypod Invoke-Command -ComputerName X -ScriptBlock { Write-Host $args[0] } -ArgumentList $var1 Commented Mar 30, 2022 at 15:11

1 Answer 1

1

As suggested by Dilly B:

You can pass the argument to Invoke-Command to reach to variables in variable group:

$var1 = $env:Mypod  
Invoke-Command -ComputerName X -ScriptBlock { Write-Host $args[0] } -ArgumentList $var1 

You can refer to Use a variable group's secret and nonsecret variables in an Azure Pipeline and Azure DevOps: how to manage CI/CD variable groups using PowerShell

Sign up to request clarification or add additional context in comments.

1 Comment

and if I have 2 arguments , how can I set them in the list of argument list ? like that : -ArgumentList $var1, $var2? and use arg[0] \ arg[1]?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.