Pass a argument with variable to cmd

Welcome Forums General PowerShell Q&A Pass a argument with variable to cmd

Viewing 5 reply threads
  • Author
    Posts
    • #201041
      Participant
      Topics: 3
      Replies: 3
      Points: 45
      Rank: Member

      Hello,

      I’m wondering how to pass a variable in a argument for cmd.exe. The variable $Java Pathin below command is not recognized as variable rather as a text.

       

      $AppVName = 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 $Java_Pfad /f
      }

       

    • #201044
      Participant
      Topics: 4
      Replies: 1908
      Points: 4,259
      Helping Hand
      Rank: Community Hero

      There are a few options to pass arguments to script blocks: Get-Help about_Script_Blocks.

      BTW: You don’t need to use cmd to manipulate the registry … Powershell is easily able to do that internally. 😉

    • #201047
      Participant
      Topics: 3
      Replies: 3
      Points: 45
      Rank: Member

      There are a few options to pass arguments to script blocks: Get-Help about_Script_Blocks.

      BTW: You don’t need to use cmd to manipulate the registry … Powershell is easily able to do that internally. 😉

      Thanks, I tried the prefix “$_.” but it doesn’t work. Any idea why?

       

      $AppVName = 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 {$_.Java_Pfad} /f
      }

    • #201053
      Participant
      Topics: 4
      Replies: 1908
      Points: 4,259
      Helping Hand
      Rank: Community Hero

      Lothar,

      sorry, I sent you the wrong help topic. I’ve had a wrong connection in my mind. Please take a look at the paragraph “Using local variables” of the help topic about_Remote_Vriables.

      Most of the time it works with the $Using: scope modifier.

    • #201083
      js
      Participant
      Topics: 28
      Replies: 772
      Points: 2,220
      Helping Hand
      Rank: Community Hero

      In powershell it would be:

      set-itemproperty HKCU:\Software\FRS\FiRE\Defaults JREPath $Java_Pfad
      

      If you really wanted to use cmd:

      cmd /c REG ADD HKEY_CURRENT_USER\Software\FRS\FiRE\Defaults /v JREPath /d $Java_Pfad /f
      
      • This reply was modified 1 month, 4 weeks ago by js.
      • This reply was modified 1 month, 4 weeks ago by js.
      • This reply was modified 1 month, 4 weeks ago by js.
    • #201303
      Participant
      Topics: 3
      Replies: 3
      Points: 45
      Rank: Member

      Ok, I try to figure this out with Powershell using set-itemproperty.

      In cmd I’ve loaded the virtual registry with below command: cmd.exe /appvve:ef1af223-8cc4-4622-a8c2-cd5af4308d05_e3394101-18b5-4679-86da-76a2209b2a81.

      How can I reach this with Powershell, means first I have to load the virtual registry and hereafter to change this registry with using set-itemproperty?

       

Viewing 5 reply threads
  • You must be logged in to reply to this topic.