get-hotfix не работает на Powershell v1 .... нужна альтернатива - PullRequest
1 голос
/ 11 ноября 2011

У меня есть код ниже, который выполняет различные действия и проверяет информацию об исправлениях.Я пробовал на серверах Windows Server 2008 с пакетом обновления 2 (SP2), и на них не установлен Powershell v2.Таким образом, вместо того, чтобы просмотреть мое состояние и исправить это на данный момент (есть более 3000 серверов SP2 2008) - мне нужно изменить свой код.

Я знаю, что Win32_quickfixengineering может делать то же самое, но не совсем уверен, чтоя должен изменить в своем коде - любая помощь, пожалуйста:

$computerdel = gc env:computername

$t = "C:\buildlog\$(gc env:computername).log"
#$e = Test-Path $t
rm $t -ErrorAction SilentlyContinue

#if ( $e -eq $true ) { rm $t }
#else { Write-Host "Shortcut does not exist." }


$Logfile = "C:\buildlog\$(gc env:computername).log"

Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}

LogWrite -----------------------------------------------------------------------------------------------------------------------------------------------

$computer = gc env:computername
$Date = Get-Date
$ExecutionpolicySET = Set-ExecutionPolicy Unrestricted
$OSVersion = Get-WmiObject Win32_operatingsystem

LogWrite "Script has been run on $Date - This is Servers Local Time"
LogWrite $computer
LogWrite "Server type: "
LogWrite $OSVersion.name

$onetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMajorPart).tostring()
$twotcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMinorPart).tostring() 
$threetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductBuildPart).tostring() 
$fourtcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductPrivatePart).tostring() 

$onedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMajorPart).tostring() 
$twodfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMinorPart).tostring() 
$threedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductBuildPart).tostring() 
$fourdfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductPrivatePart).tostring()

$hotfix1 = Get-HotFix -Id KB2450944 -ErrorAction SilentlyContinue 
$hotfix2 = Get-HotFix -Id KB2582284 -ErrorAction SilentlyContinue
$hotfix3 = Get-HotFix -Id KB979808 -ErrorAction SilentlyContinue
$hotfix4 = Get-HotFix -Id KB2121690 -ErrorAction SilentlyContinue
$hotfix5 = Get-HotFix -Id KB973776 -ErrorAction SilentlyContinue
$hotfix6 = Get-HotFix -Id KB953325 -ErrorAction SilentlyContinue
$hotfix7 = Get-HotFix -Id KB977357 -ErrorAction SilentlyContinue
$hotfix8 = Get-HotFix -Id KB2505348 -ErrorAction SilentlyContinue
$hotfix9 = Get-HotFix -Id KB2285835 -ErrorAction SilentlyContinue
$hotfix10 = Get-HotFix -Id KB976655 -ErrorAction SilentlyContinue
$hotfix11 = Get-HotFix -Id KB979564 -ErrorAction SilentlyContinue
$hotfix12 = Get-HotFix -Id KB962969 -ErrorAction SilentlyContinue

LogWrite

    If ($hotfix1) {
        LogWrite "Hotfix KB2450944 is installed - This is DFSRS.exe Upgrade Hotfix" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB2450944 is NOT installed - Please ensure you install this hotfix - This is DFSRS.exe Upgrade Hotfix" -ForegroundColor "red"
    }
    LogWrite "DFSRS.exe Version on $computer is: ""$onedfsr.$twodfsr.$threedfsr.$fourdfsr"" "

LogWrite

    If ($hotfix4) {
        LogWrite "Hotfix KB2121690 is installed - This is 20 CPU Patch" -BackgroundColor Green -ForegroundColor Black
    }
    else {
    LogWrite "Hotfix KB2121690 is NOT installed - This is 20 CPU Patch" -ForegroundColor "red"
}

LogWrite

If ($OSVersion.version -eq "6.0.6002") 
{
    If ($hotfix5) {
        LogWrite "Hotfix KB973776 is installed - This is Robocopy Upgrade Hotfix" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB973776 is NOT installed - This is Robocopy Upgrade Hotfix" -ForegroundColor "red"
    }

    If ($hotfix6) {
        LogWrite "Hotfix KB953325 is installed - Resolves Paged Pool Exhusion Issue" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB953325 is NOT installed - Resolves Paged Pool Exhusion Issue" -ForegroundColor "red"
    }
    If ($hotfix12) {
        LogWrite "Hotfix KB962969 is installed - Resolves Command Line error on DFSRadmin.exe" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB962969 is NOT installed - Resolves Command Line error on DFSRadmin.exe" -ForegroundColor "red"
    }

}

ElseIf ($OSVersion.version -eq "6.1.7600")
{

    If ($hotfix2) {
        LogWrite "Hotfix KB2582284 is installed - This is TCPIP.sys Upgrade Hotfix" -BackgroundColor Green -ForegroundColor Black
        }
    else {
        LogWrite "Hotfix KB2582284 is NOT installed - Please ensure you install this hotfix - This is DFSRS.exe Upgrade Hotfix" -ForegroundColor "red"
        }

    LogWrite "TCPIP.sys Version on $computer is: ""$onetcp.$twotcp.$threetcp.$fourtcp"" "

LogWrite

    If ($hotfix3) {
        LogWrite "Hotfix KB979808 is installed - This is Robocopy R2 Pre-Seeding Upgrade" -BackgroundColor Green -ForegroundColor Black
        }
    else {
        LogWrite "Hotfix KB979808 is NOT installed - This is Robocopy R2 Pre-Seeding Upgrade" -ForegroundColor "red"
    }
LogWrite
    If ($hotfix7) {
        LogWrite "Hotfix KB977357 is installed - Resolves Memory Leak on WMI" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB977357 is NOT installed - Resolves Memory Leak on WMI" -ForegroundColor "red"
    }
LogWrite
    If ($hotfix8) {
        LogWrite "Hotfix KB2505348 is installed - Resolves Performance issues on WMI" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB2505348 is NOT installed - Resolves Performance issues on WMI" -ForegroundColor "red"
    }
LogWrite
If ($hotfix10) {
        LogWrite "Hotfix KB976655 is installed - Update for dfsro.dll" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB976655 is NOT installed - Update for dfsro.dll" -ForegroundColor "red"
    }
LogWrite
If ($hotfix11) {
        LogWrite "Hotfix KB979564 is installed - Dfsrclus.dll update" -BackgroundColor Green -ForegroundColor Black
    }
    else {
        LogWrite "Hotfix KB979564 is NOT installed - Dfsrclus.dll update" -ForegroundColor "red"
    }


LogWrite -----------------------------------------------------------------------------------------------------------------------------------------------

1 Ответ

2 голосов
/ 13 ноября 2011

Командлет Get-Hotfix при вызове с параметром -Id выполняет запрос wmi для каждого идентификатора в этом параметре с этим идентификатором в предложении where запроса wmi.

Командлет Get-Hotfix выбрасываетошибка, когда не найдено исправлений, соответствующих вашим критериям.Для подавления сообщения об ошибке вы можете добавить -ErrorAction SilentlyContinue

При выполнении запроса wmi с использованием Get-WmiObject -query не выдается ошибка, если не найдено объектов, соответствующих критериям в запросе.

Этоозначает, что следующие два оператора эквивалентны (второй также будет работать в Powershell v1):

Get-HotFix -Id KB2450944 -ErrorAction SilentlyContinue
Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2450944'"

В вашем коде вы должны заменить этот блок кода:

$hotfix1 = Get-HotFix -Id KB2450944 -ErrorAction SilentlyContinue 
$hotfix2 = Get-HotFix -Id KB2582284 -ErrorAction SilentlyContinue
$hotfix3 = Get-HotFix -Id KB979808 -ErrorAction SilentlyContinue
$hotfix4 = Get-HotFix -Id KB2121690 -ErrorAction SilentlyContinue
$hotfix5 = Get-HotFix -Id KB973776 -ErrorAction SilentlyContinue
$hotfix6 = Get-HotFix -Id KB953325 -ErrorAction SilentlyContinue
$hotfix7 = Get-HotFix -Id KB977357 -ErrorAction SilentlyContinue
$hotfix8 = Get-HotFix -Id KB2505348 -ErrorAction SilentlyContinue
$hotfix9 = Get-HotFix -Id KB2285835 -ErrorAction SilentlyContinue
$hotfix10 = Get-HotFix -Id KB976655 -ErrorAction SilentlyContinue
$hotfix11 = Get-HotFix -Id KB979564 -ErrorAction SilentlyContinue
$hotfix12 = Get-HotFix -Id KB962969 -ErrorAction SilentlyContinue

наэтот блок кода:

$hotfix1 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2450944'" 
$hotfix2 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2582284'"
$hotfix3 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB979808'"
$hotfix4 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2121690'"
$hotfix5 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB973776'"
$hotfix6 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB953325'"
$hotfix7 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB977357'"
$hotfix8 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2505348'"
$hotfix9 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB2285835'"
$hotfix10 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB976655'"
$hotfix11 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB979564'"
$hotfix12 = Get-WmiObject -Query "Select * from Win32_QuickFixEngineering where HotFixID= 'KB962969'"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...