Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
System Center Configuration Manager
»
Slideshow
System Center Configuration Manager Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
AD
Advertisements
DNS
Packages
Powershell
Programs
SCCM
Software Distribution
SQL query
WSUS
View more
WSUS_AutoDownload_Approve_Decline
<
# Establising Connection to WSUS Server#>
[
void
][
reflection.assembly
]::
LoadWithPartialName
(
"Microsoft.UpdateServices.Administration"
)
[
void
][
System.Reflection.Assembly
]::
LoadWithPartialName
(
'Microsoft.VisualBasic'
)
$wsus
=
[
Microsoft.UpdateServices.Administration.AdminProxy
]::
GetUpdateServer
();
<
# These Commands will Show the Synchronization Progress details#>
$sub
=
$wsus
.
GetSubscription
()
$Msg1
=
[
Microsoft.VisualBasic.Interaction
]::
MsgBox
(
"Do you want to Start Synchronization?"
,
'YesNo,Question'
,
"WSUS Automation - Team IT"
)
$a
=
new-object
-comobject
wscript.shell
$LastSync
=
$Sub
.
LastSynchronizationTime.tostring
(
'MM/dd/yyyy'
)
Switch
(
"$Msg1"
)
{
'Yes'
{
$sub
.
StartSynchronization
();
do
{
$a
.
popup
(
"Synchronization is in Progress."
,7,
"WSUS Automation - Team IT"
)
Start-Sleep
-Seconds
3
$Status
=
$sub
.
GetSynchronizationProgress
()
}
until
(
$Status
.
Phase
-like
"*NotProcessing*"
)
}
'No'
{
$a
.
popup
(
"Last Sync - $LastSync"
,7,
"WSUS Automation - Team IT"
)}
}
#$sub.StartSynchronization()
#Write-Host "Synchronization have been started."
#Start-Sleep -Seconds 3
#$sub.GetSynchronizationProgress()
#[Array] $SyncDetails = $sub.GetSynchronizationHistory()
$sub
=
$wsus
.
GetSubscription
()
$LastSync
=
$Sub
.
LastSynchronizationTime.tostring
(
'MM/dd/yyyy'
)
$LastSyncPatches
=
$wsus
.
getupdates
() |
Select-Object
Title,ArrivalDate,IsDeclined,IsApproved |
Where-object
{
$_
.
ArrivalDate
-like
"*$LastSync*"
-and
$_
.
IsDeclined
-like
"False"
}
#<All the Latest Sync patches details will be saved in C:\>#
$LastSyncPatches
|FT Title > C:\
$
(
$
(
get-date
).
tostring
(
'MM-dd-yyyy'
))_FullDetails_LastSyncPatches.
txt
$a
.
popup
(
"Full Patches details are saved @ patch C:\$($(get-date).tostring('MM-dd-yyyy'))_FullDetails_LastSyncPatches.txt "
,7,
"WSUS Automation - Team IT"
)
############Code to Decline Unwanted Patches############
$ItaniumPatches
=
$LastSyncPatches
|
Select-Object
Title,ArrivalDate,IsDeclined |
Where-object
{
$_
.
Title
-like
"*Itanium*"
-and
$_
.
ArrivalDate
-like
"*$LastSync*"
-and
$_
.
Isdeclined
-like
"False"
}
$ItaniumPatches
|FT Title > C:\
$
(
$
(
get-date
).
tostring
(
'MM-dd-yyyy'
))_Declined_ItaniumPatches_Details.
txt
$a
.
popup
(
"Itanium Patches to be Declined are saved @ C:\$($(get-date).tostring('MM-dd-yyyy'))_Declined_ItaniumPatches_Details.txt "
,5,
"WSUS Automation - Team IT"
)
$Msg2
=
[
Microsoft.VisualBasic.Interaction
]::
MsgBox
(
"'YES' to decline Itanium Patches - 'NO' to Approve Itanium Patches ?"
,
'YesNo,Question'
,
"WSUS Automation - Team IT"
)
switch
(
"$Msg2"
)
{
'Yes'
{
foreach
(
$ItaniumPatche
in
$ItaniumPatches
)
{
$ItanDecline
=
$ItaniumPatche
.
Title
#$PatDecline = $wsus.Searchupdates("$ItanDecline")
$PatDecline
=
$wsus
.
getupdates
() |
Select-Object
|
where-object
{
$_
.
Title
-eq
"$ItanDecline"
-and
$_
.
Isdeclined
-like
"False"
-and
$_
.
IsApproved
-like
"False"
}
$PatDecline
.
Decline
(
$True
)
Write-Host
$ItaniumPatche
.
Title
"- has been Declined"
$ItanDecline
=
$Null
}
}
'No'
{}
}
############Code to Approve the Patches###################
$Action
=
[
Microsoft.UpdateServices.Administration.UpdateApprovalAction
]::
Install
$LastSyncPatches_Approves
=
""
$LastSyncPatches_Approves
=
$wsus
.
getupdates
() |
Select-Object
Title,ArrivalDate,IsDeclined,IsApproved |
Where-object
{
$_
.
ArrivalDate
-like
"*$LastSync*"
-and
$_
.
Isdeclined
-like
"False"
-and
$_
.
Isapproved
-like
"False"
}
$LastSyncPatches_Approves
|FT Title > C:\
$
(
$
(
get-date
).
tostring
(
'MM-dd-yyyy'
))_TO_Approve
-
Patches_Details.txt
$ToApprove
=
$LastSyncPatches_Approves
|FT Title
$a
.
popup
(
"Remove the Patches from the List which should not be Approved - Available @ patch C:\$($(get-date).tostring('MM-dd-yyyy'))_FullDetails_LastSyncPatches.txt "
,7,
"WSUS Automation - Team IT"
)
$Msg3
=
[
Microsoft.VisualBasic.Interaction
]::
MsgBox
(
"'YES' to Confirm for Go-Ahead ? - 'NO' for Exit"
,
'YesNo,Question'
,
"WSUS Automation - Team IT"
)
$Targetgroup
=
(
$wsus
.
GetComputerTargetGroups
() | ? {
$_
.
Name
-eq
"Preinstall"
})
switch
(
"$Msg3"
)
{
'Yes'
{
[
Array
]
$PatchApprove
=
Get-content
"C:\$($(get-date).tostring('MM-dd-yyyy'))_TO_Approve-Patches_Details.txt"
$Incr
=
3
$lpEnd
=
$PatchApprove
.
count
-
2
do
{
$ApprovedPat
=
$PatchApprove
[
$incr
].
trimend
()
$PatAppr
=
$wsus
.
getupdates
() |
Select-object
|
where-object
{
$_
.
Title
-like
"*$ApprovedPat*"
-and
$_
.
Isdeclined
-like
"False"
-and
$_
.
IsApproved
-like
"False"
}
$PatAppr
.
Approve
(
$Action
,
$Targetgroup
) |
out-null
Write-Host
$PatchApprove
[
$incr
]
"- has been Approved"
$Incr
=
$Incr
+
1
}
until
(
$Incr
-eq
$lpEnd
)
<
#
$PatchApprove
=
Get-content
"C:\$($(get-date).tostring('MM-dd-yyyy'))_TO_Approve-Patches_Details.txt"
foreach
(
$PatchAppr
in
$PatchApprove
)
{
$PatAppr
=
$wsus
.
getupdates
() |
Select-object
|
where-object
{
$_
.
Title
-eq
"PatchAppr*"
-and
$_
.
Isdeclined
-like
"False"
-and
$_
.
IsApproved
-like
"False"
}
$PatAppr
.
Approve
(
$Action
,
$Targetgroup
) |
out-null
Write-Host
$PatchAppr
"- has been Approved"
} > c:\
PhaniTestOP.txt
#>
}
'No'
{
$a
.
popup
(
"Patches were not Approved - Exiting the Script"
,0,
"WSUS Automation - Team IT"
)
exit
}
}
Loading...
WSUS_AutoDownload_Approve_Decline
SCCM Software...
Compare All...
Go from User...
View all files
Copyright 2011 PowerShell.com. All rights reserved.