Powershell Variable Insert
1 TopicInserting variable in command string
I am trying to make a small script to get user, computer and SID info for changing a registry value. Below is my script... $computer = read-host -prompt 'Enter Computername' $user = read-host -prompt 'Enter Username' $sid = Get-Aduser -identity $user | select-object SID invoke-command -computer win7test01 -scriptblock {(New-PSDrive -psprovider registry -Name HKU -Root HKEY_USERS),(Set-ItemProperty "hku:\$sid\SOFTWARE\Microsoft\Office\16.0\Lync\printtest@contoso.com" -Name What I am trying to do is insert the SID gathered by the $sid portion which returns the correct value after running the command by itself and the typing $sid. What I am having an issue with is inserting that variable into the Set-ItemProperty portion as you can see from the line above. It fails when I run it and I am wondering if there is any way this can be done or do I have to manually modify the code and enter the SID before running the script. I am fairly new to Powershell so just wondering what the best way to accomplish this would be. Many thanks in advance!Solved7KViews1like4Comments