Update test.ps1
This commit is contained in:
24
test.ps1
24
test.ps1
@@ -235,11 +235,16 @@ function Invoke-ServiceImagePathAudit {
|
|||||||
return $outObj
|
return $outObj
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = "\\$($outObj.ComputerName)\$($outObj.Key)"
|
# Normalize root names so reg.exe remote paths are valid
|
||||||
$data = $outObj.FixedKey
|
$regKey = [string]$outObj.Key
|
||||||
|
$regKey = $regKey -replace '^HKEY_LOCAL_MACHINE', 'HKLM'
|
||||||
|
$regKey = $regKey -replace '^HKEY_USERS', 'HKU'
|
||||||
|
|
||||||
|
$target = "\\$($outObj.ComputerName)\$regKey"
|
||||||
|
$data = [string]$outObj.FixedKey
|
||||||
|
|
||||||
if ($ShowProgress) {
|
if ($ShowProgress) {
|
||||||
Write-Progress -Activity "Repairing ImagePath" -Status "Fixing $($outObj.ComputerName)\$($outObj.Key)"
|
Write-Progress -Activity "Repairing ImagePath" -Status "Fixing $($outObj.ComputerName)\$regKey"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($data) -or $data -eq 'N/A' -or $data -eq "Can't Fix") {
|
if ([string]::IsNullOrWhiteSpace($data) -or $data -eq 'N/A' -or $data -eq "Can't Fix") {
|
||||||
@@ -247,17 +252,24 @@ function Invoke-ServiceImagePathAudit {
|
|||||||
return $outObj
|
return $outObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# reg.exe needs embedded quotes escaped, and the whole /d value wrapped in quotes
|
||||||
|
# Example: "C:\Program Files\App\app.exe" /arg
|
||||||
|
# becomes: "\"C:\Program Files\App\app.exe\" /arg"
|
||||||
|
$dataEscaped = $data -replace '"', '\"'
|
||||||
|
$dataForReg = '"' + $dataEscaped + '"'
|
||||||
|
|
||||||
if ($PSCmdlet.ShouldProcess($target, "Set ImagePath to: $data")) {
|
if ($PSCmdlet.ShouldProcess($target, "Set ImagePath to: $data")) {
|
||||||
try {
|
try {
|
||||||
$args = @(
|
$args = @(
|
||||||
'ADD', $target,
|
'ADD', $target,
|
||||||
'/v', 'ImagePath',
|
'/v', 'ImagePath',
|
||||||
'/t', 'REG_EXPAND_SZ',
|
'/t', 'REG_EXPAND_SZ',
|
||||||
'/d', $data,
|
'/d', $dataForReg,
|
||||||
'/f'
|
'/f'
|
||||||
)
|
)
|
||||||
|
|
||||||
$output = & reg.exe @args 2>&1
|
$output = & reg.exe @args 2>&1
|
||||||
|
|
||||||
if ($LASTEXITCODE -eq 0) {
|
if ($LASTEXITCODE -eq 0) {
|
||||||
$outObj.Status = "Fixed"
|
$outObj.Status = "Fixed"
|
||||||
} else {
|
} else {
|
||||||
@@ -269,12 +281,14 @@ function Invoke-ServiceImagePathAudit {
|
|||||||
catch {
|
catch {
|
||||||
$outObj.Status = "Failed: $($_.Exception.Message)"
|
$outObj.Status = "Failed: $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$outObj.Status = "WhatIf"
|
$outObj.Status = "WhatIf"
|
||||||
}
|
}
|
||||||
|
|
||||||
return $outObj
|
return $outObj
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
|
|||||||
Reference in New Issue
Block a user