I started a script with script-block:
[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'qmenable' -Value 0 -Type DWord -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'updatereliabilitydata' -Value 1 -Type DWord -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name 'blabla' -Value 1 -Type DWord -SID $UserProfile.SID
}
So this is what it must look.
OK, but I need a variable.
$HKCURegistrySettings2 = {
@"
set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'qmenable' -Value 0 -Type DWord -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Office\14.0\Common' -Name 'updatereliabilitydata' -Value 1 -Type DWord -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce' -Name `'$test`' -Value 1 -Type DWord -SID $UserProfile.SID
"@
}
So I replace blabla
by $test
.
$test="blabla"
$test3=&$HKCURegistrySettings2
$test3
[ScriptBlock]$HKCURegistrySettings3 = [ScriptBlock]::Create($test3)
$HKCURegistrySettings -eq $HKCURegistrySettings3
So now by comparing my first $HKCURegistrySettings
and my now $HKCURegistrySettings3
They should be the same. But I get a false. 1. Why are they different? 2. How may I get to make them identical? 3. The variables are define AFTER the Here-strings creation. Other option?
When the scriptblock is create it is then use to call a function Initially:
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings
and now
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings3
So this is why the result should be the same.
Thanks,