Pass a argument with variable to cmd

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
}

 

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. :wink:

[quote quote=201044]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. 😉

[/quote]
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
}

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.

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

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?