1 year ago
#319313
Bajan
New-ItemProperty only runs locally, not when remotely via Invoke-Command?
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!
windows
powershell
invoke-command
0 Answers
Your Answer