Hi all
I created the following script to add a new registry key, but it didn’t work. I checked the action info log on BigFix, all tasks show as completed. However, when I manually opened the registry, there were no changes.I am using PowerShell to execute it. Is there something wrong there? Does anyone have better suggestions or methods?
parameter “RegistryPath1” = “HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server”
parameter “RegistryPath2” = “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server”
parameter “ValueName” = “ROWGUID”
parameter “ValueData” = “ADB43860-2506-45BE-9792-83BC3D95CEA6”
createfile until end-of-script
$registryPath1 = “{parameter “RegistryPath1”}”
$registryPath2 = “{parameter “RegistryPath2”}”
$valueName = “{parameter “ValueName”}”
$valueData = “{parameter “ValueData”}”
function CheckAndAddRowGuid {
param (
[string]$path
)
try {
if (Test-Path $path) {
$existingValue = Get-ItemProperty -Path $path -Name $valueName -ErrorAction SilentlyContinue
if ($existingValue -eq $null) {
Set-ItemProperty -Path $path -Name $valueName -Value $valueData -ErrorAction Stop
Write-Host "Added ROWGUID: $valueData at Location: $path"
} else {
Write-Host "ROWGUID exists: $($existingValue.$valueName) at Location: $path"
}
} else {
Write-Host "Key does not exist: $path"
New-Item -Path $path -Force | Out-Null
Write-Host "Created registry key: $path"
Set-ItemProperty -Path $path -Name $valueName -Value $valueData -ErrorAction Stop
Write-Host "Added ROWGUID: $valueData at Location: $path"
}
} catch {
Write-Host "Error occurred: $_"
}
}
CheckAndAddRowGuid -path $registryPath1
CheckAndAddRowGuid -path $registryPath2
end-of-script
move __createfile “C:\Temp\AddRowGuid.ps1”
action uses wow64 redirection false
wait powershell.exe -NoProfile -ExecutionPolicy Bypass -File “C:\Temp\AddRowGuid.ps1”