Pass parameter in invoke-command

Welcome Forums General PowerShell Q&A Pass parameter in invoke-command

Viewing 1 reply thread
  • Author
    • #202940
      Topics: 3
      Replies: 3
      Points: 45
      Rank: Member

      Hello, I want to pass a path string with a parameter $p1  in below invoke-command but unfortunately it’s not working. Any idea why?

      $Java_Pfad= "C:\Program Files (x86)\Java\jre1.8.0_231"
      $AppVName = Get-AppvClientPackage -PackageId ef1af223-8cc4-4622-a8c2-cd5af4308d05
      Invoke-Command -ScriptBlock { param($p1)
      Get-AppvClientPackage -PackageId ef1af223-8cc4-4622-a8c2-cd5af4308d05
      Start-AppvVirtualProcess -AppvClientObject $AppVName cmd.exe {/k
      REG ADD HKEY_CURRENT_USER\Software\FRS\FiRE\Defaults /v JREPath /t REG_SZ /d $p1 /f}
      } -ArgumentList $Java_Pfad
      • This topic was modified 1 month, 2 weeks ago by kvprasoon. Reason: code formatting
    • #202955
      Topics: 12
      Replies: 1489
      Points: 1,987
      Helping Hand
      Rank: Community Hero

      It’s not the path that is the issue, it is that you are referencing a local variable $AppVName, so the AppvClientObject is NULL. The Get-AppcClientPackage in the scriptblock is not assigned to the variable $AppVName. You can also use the $Using scope modifier:

Viewing 1 reply thread
  • You must be logged in to reply to this topic.