Pass parameter in invoke-command

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

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: