-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCCMSoftwareUpdateGroup.ps1
More file actions
89 lines (81 loc) · 3.3 KB
/
Copy pathSCCMSoftwareUpdateGroup.ps1
File metadata and controls
89 lines (81 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# List of Updates to SoftwareUpdateGroup Script
# Dudu D / AgileIT
#
### Declare Parameters for the script and validate they are not empty
Param(
[ValidateNotNullorEmpty()]
[string]$Scan,
[ValidateNotNullorEmpty()]
[string]$UpdatesFile,
[ValidateNotNullorEmpty()]
[string]$SUG,
[ValidateNotNullorEmpty()]
[string]$Logfile
)
### Verify PowerShell Version
$hostVersionInfo = (Get-Host).Version.Major
If ($hostVersionInfo -lt 3)
{
Throw "You are using PowerShell $hostVersionInfo. In order to run this script it is required to use PowerShell 3 and up."
}
### Verify that PowerShell instance is x86
If ([Environment]::Is64BitProcess -eq $True) {
Throw "ConfigMgr 2012 can be loaded only in PowerShell x86"
}
### Error Handling
$ErrorActionPreference = "SilentlyContinue"
### Load The SCCM 2012 Module
Set-ExecutionPolicy RemoteSigned -Force
$CMModulePath = $Env:SMS_ADMIN_UI_PATH.ToString().SubString(0,$Env:SMS_ADMIN_UI_PATH.Length - 5) + "\ConfigurationManager.psd1"
If (-not (Get-Module ConfigurationManager)) {
Write-Host -ForegroundColor "Green" -BackgroundColor DarkGreen "Loading System Center Configuration Manager Module...."
Import-Module $CMModulePath -Verbose
$CMPSDrive = Get-PSDrive -PSProvider CMSite
Set-Location "$($CMPSDrive):"
}
If($Scan) {
Write-Host "$NULL"
Write-Host "Searching for Updates containing the following string: $Scan"
Get-CMSoftwareUpdate -Name *$Scan* | Set-Variable ScanResults
If (!$ScanResults) {
Write-Host "No Updates for the following string were found $Scan"
Exit
}
Else {
$ScanResults | select LocalizedDisplayName, ArticleID, CI_ID | Format-Table -AutoSize
Exit
}
$Scan = $NULL
}
If (!$UpdatesFile) {
Write-Host "$NULL"
Write-Host "A path to gather a list of updates from must be specifed using -UpdatesFile"
Write-Host "Syntax usage is: SCCMSoftwareUpdateGroup.ps1 -UpdatesFile ""C:\temp\list1.txt"" -SUG ""Software Update Group 5"" -Logfile ""C:\Temp\Logfile.txt"""
Exit
}
If (($UpdatesFile) -and (!$SUG)) {
Write-Host "$NULL"
Write-Host "Please provide a Software Update Group Name using -SUG"
Write-Host "Syntax usage is: SCCMSoftwareUpdateGroup.ps1 -UpdatesFile ""C:\temp\list1.txt"" -SUG ""Software Update Group 5"" -Logfile ""C:\Temp\Logfile.txt"""
Exit
}
Else {
$CMPSDrive = Get-PSDrive -PSProvider CMSite
$Updates = Get-Content $UpdatesFile | ? {$_.trim() -ne "" }
foreach ($Update in $Updates) {
If ($Logfile) {
Add-CMSoftwareUpdateToGroup -SoftwareUpdateGroupName $SUG -SoftwareUpdateName *$Update* -ErrorAction SilentlyContinue
If ($?) {
Write-Host -ForegroundColor "Green" -BackgroundColor DarkGreen KB$Update added sucessfully
Write-Output "[OK] KB$Update added sucessfully" | Out-File -append -filepath $Logfile }
Else {
Write-Host -Background "Black" -ForegroundColor "Red" KB$Update failed to add.
Write-Output "[BAD] KB$Update Failed." | Out-File -append -filepath $Logfile }
}
Else {
If ($?)
{ Write-Host -ForegroundColor "Green" -BackgroundColor DarkGreen KB$Update added sucessfully }
Else { Write-Host -Background "Black" -ForegroundColor "Red" KB$Update failed to add. }
}
}
}