Update test.ps1
This commit is contained in:
24
test.ps1
24
test.ps1
@@ -235,11 +235,16 @@ function Invoke-ServiceImagePathAudit {
|
||||
return $outObj
|
||||
}
|
||||
|
||||
$target = "\\$($outObj.ComputerName)\$($outObj.Key)"
|
||||
$data = $outObj.FixedKey
|
||||
# Normalize root names so reg.exe remote paths are valid
|
||||
$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) {
|
||||
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") {
|
||||
@@ -247,17 +252,24 @@ function Invoke-ServiceImagePathAudit {
|
||||
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")) {
|
||||
try {
|
||||
$args = @(
|
||||
'ADD', $target,
|
||||
'/v', 'ImagePath',
|
||||
'/t', 'REG_EXPAND_SZ',
|
||||
'/d', $data,
|
||||
'/d', $dataForReg,
|
||||
'/f'
|
||||
)
|
||||
|
||||
$output = & reg.exe @args 2>&1
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$outObj.Status = "Fixed"
|
||||
} else {
|
||||
@@ -269,12 +281,14 @@ function Invoke-ServiceImagePathAudit {
|
||||
catch {
|
||||
$outObj.Status = "Failed: $($_.Exception.Message)"
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$outObj.Status = "WhatIf"
|
||||
}
|
||||
|
||||
return $outObj
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
Reference in New Issue
Block a user