I am trying to modify existing registry key values on remote machines. When I run the following, the targeted registry keys that are supposed to change to the new "AU" instead have their values cleared out.
$AU = Read-Host -Prompt 'Enter AU "Ex: AU00325"'
#Changes Registry Keys
Invoke-Command -ComputerName $Computers -ScriptBlock {
New-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WFB -Force | New-ItemProperty -Name "Branch" -Value $AU -Force | Out-Null ;
New-Item -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\WFB -Force | New-ItemProperty -Name "Branch" -Value $AU -Force | Out-Null ;
New-Item -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\WFB -Force | New-ItemProperty -Name "Branch" -Value $AU -Force | Out-Null ;
}
It looks like the variables aren't carrying over when using invoke command. I verified this by using the -Value "Test" instead of $AU, and that worked fine. Is there a way to make Invoke-Command use variables that are set in previous lines?