0

I am trying to set a registry value on a remote Windows 2019 domain joined machine. When I RDP into the machine I can run the following to change the registry value locally from that machine:

Example in this case I am trying to set the value of displayname to my variable $test:

$test = 'whatever'
New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\CompanyA\SoftwareA\connectiontyp -PropertyType String -Name displayname -Value $test -Force

However when I try to update this on a remote machine, example:

$test = 'whatever'
$computer = 'remotepc.domain.local'
invoke-command -ComputerName $computer -ScriptBlock { New-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\CompanyA\SoftwareA\connectiontyp -PropertyType String -Name displayname -Value $test -Force}

I am using the -Force flag to forcefully overwrite the value, if not I would have attempted using Set-ItemProperty.(Which I quickly also just tried and also did not work remotely...)

Thank you!

Mofi
  • 46,139
  • 17
  • 80
  • 143
Bajan
  • 634
  • 3
  • 12
  • 30
  • 2
    `$test` doesn't exist in the remote scope, you need to use `$using:test` if you want to call a variable defined on the local scope remotely – Santiago Squarzon Mar 22 '22 at 02:32
  • 1
    You are CORRECT! I've been looking at it for so long and it never even clicked. THANK YOU! – Bajan Mar 22 '22 at 03:43

0 Answers0