mardi 21 avril 2015

Changing registry binary value in IF statement

I am having problem with this IF statement.

Trying to change OUTLOOK 2013 Theme. It works but the correct write-host is not working or it's not reading the value correctly.

#OUTLOOK
Push-Location
    Set-Location (Join-Path 'HKCU:\Software\Microsoft\Office\15.0\Common\Roaming\Identities' -ChildPath '*companyname.com*\Settings\1170\{00000000-0000-0000-0000-000000000000}\PendingChanges' -Resolve)
  
$val = Get-ItemProperty -Path . -Name "Data" 
if($val."Data" -eq ([byte[]](0x02,0x00,0x00,0x00)))
{
    Write-Host "Microsoft Office Theme:" -NoNewline; Write-Host "....Dark Grey Theme has been set " -ForegroundColor Green -BackgroundColor Black
    Write-Output "Office theme: Dark Grey already set..no changes needed" | Out-File -FilePath "$LogPath\$env:ComputerName.log" -Append -NoClobber
} else {
set-itemproperty -Path . -Name "Data" -Value ([byte[]](0x02,0x00,0x00,0x00)) -Force
    Write-Host "Microsoft Office Theme:" -NoNewline; Write-Host "....Dark Grey Theme already set " -ForegroundColor Cyan -BackgroundColor Black
    Write-Output "Office theme: Dark Grey has been set" | Out-File -FilePath "$LogPath\$env:ComputerName.log" -Append -NoClobber
}
Pop-Location

I can get it work when I change the common\'UI Theme' as that is a dword value with only a single digit. The script for that works fine But because outlook is synced with the server, have to change the roaming identity. When I run this script, it would always say "Dark grey already set' even though it hasn't. It would change it but just wrong message. I also had it reversed using -ne and -binary but same issue.

if($val."Data" -ne 02,00,00,00)
{
 set-itemproperty -Path . -Name "Data" -Value 02,00,00,00 -Type Binary -Force

So basically, it partially works, just want to display the correct message. I am still a n00b at powershell (been only using/learning it for a week), so please be gentle. If you can tell me what I am missing or why its not working, that would be great :D

Cheers Adam

Aucun commentaire:

Enregistrer un commentaire