使用PowerShell禁用自动更新

时间:2011-04-15 20:54:47

标签: windows powershell

我想知道如何在Windows机器上禁用PowerShell自动更新。

提前致谢!

3 个答案:

答案 0 :(得分:6)

这里有几个设置和获取Windows Update配置的功能

$SCRIPT:AutoUpdateNotificationLevels= @{   

0="Not configured"; 
1="Disabled"; 
2="Notify before download";
3="Notify before installation"; 
4="Scheduled installation"

}

$SCRIPT:AutoUpdateDays=@{
0="Every Day"; 
1="Every Sunday"; 
2="Every Monday"; 
3="Every Tuesday"; 
4="Every Wednesday";
5="Every Thursday"; 
6="Every Friday"; 
7="Every Saturday"
}


Function Get-WindowsUpdateConfig
{
    $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
    $AUObj = New-Object -TypeName System.Object

    Add-Member -inputObject $AuObj -MemberType NoteProperty -Name "NotificationLevel"  `
               -Value $AutoUpdateNotificationLevels[$AUSettings.NotificationLevel]

    Add-Member -inputObject $AuObj -MemberType NoteProperty -Name "UpdateDays" `
               -Value $AutoUpdateDays[$AUSettings.ScheduledInstallationDay]

    Add-Member -inputObject $AuObj -MemberType NoteProperty -Name "UpdateHour"   `
               -Value $AUSettings.ScheduledInstallationTime 

    Add-Member -inputObject $AuObj -MemberType NoteProperty -Name "Recommended updates" `
               -Value $(IF ($AUSettings.IncludeRecommendedUpdates) {"Included"}  else {"Excluded"})
    $AuObj
 } 

Function Set-WindowsUpdateConfig
{
Param (

[Parameter()]
[ValidateRange(0,4)]
[int]
$NotificationLevel , 

[Parameter()]
[ValidateRange(0,7)]
[int]
$Day, 

[Parameter()]
[ValidateRange(0,24)]
[int]
$hour, 

[Parameter()]
[bool]
$IncludeRecommended
)

 $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
 if ($NotificationLevel)  {$AUSettings.NotificationLevel        =$NotificationLevel}
 if ($Day)                {$AUSettings.ScheduledInstallationDay =$Day}
 if ($hour)               {$AUSettings.ScheduledInstallationTime=$hour}
 if ($IncludeRecommended) {$AUSettings.IncludeRecommendedUpdates=$IncludeRecommended}
 $AUSettings.Save()
} 

答案 1 :(得分:2)

这是一个链接以及如何设置注册表设置

# http://support.microsoft.com/kb/328010

New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows -Name WindowsUpdate
New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name AU
New-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoUpdate -Value 1

答案 2 :(得分:0)

您可以使用 CMD 命令:

 sc stop wuauserv