# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
# Rikard Ronnkvist / snowland.se
# Stephane van Gulick / PowerShellDistrict.Com
# Usage:
# Save the file as SCCM-Commands.psm1
# PS:>Import-Module SCCM-Commands
# PS:>Get-SCCMCommands
#
# Current Version : 1.0
#
# 2009-04-07 Michael Niehaus Original code posted at http://blogs.technet.com/mniehaus/
# 2010-03-10 Rikard Ronnkvist Major makeover and first snowland.se release
# …
# 2013-11-13 Stéphane van Gulick New Functions: [Software Update Packages]: Get-SCCMSoftwareUpdatesGroup, Get-SCCMSoftwareUpdate, New-SCCMSoftwareUpdatePackage, Remove-SCCMSoftwareUpdatePackage,Add-SCCMSoftwareUpdateToSoftwareUpdatePackage, Remove-SCCMSoftwareUpdateFromSoftwareUpdatePackage, Get-SCCMSoftwareUpdatesPackageSourcePath
# New Functions:[Software Update Lists] : Get-SCCMSoftwareUpdateList, Update-SCCMSoftwareUpdateList, New-SCCMSoftwareUpdateList,Remove-SCCMSoftwareUpdateList
# New Functions:[Software Update Deployments] : Get-SCCMSoftwareUpdateDeployment, New-SCCMSoftwareUpdateDeployment, Remove-SCCMSoftwareUpdateDeployment
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#Region BaseCommands
Function Get-SCCMCommands {
# List all SCCM-commands
[CmdletBinding()]
PARAM ()
PROCESS {
return Get-Command -Name *-SCCM* -CommandType Function | Sort-Object Name | Format-Table Name, Module
}
}
Function Connect-SCCMServer {
# Connect to one SCCM server
[CmdletBinding()]
PARAM (
[Parameter(Mandatory=$false,HelpMessage=“SCCM Server Name or FQDN”,ValueFromPipeline=$true)][Alias(“ServerName”,“FQDN”,“ComputerName”)][String] $HostName = (Get-Content env:computername),
[Parameter(Mandatory=$false,HelpMessage=“Optional SCCM Site Code”,ValueFromPipelineByPropertyName=$true )][String] $siteCode = $null,
[Parameter(Mandatory=$false,HelpMessage=“Credentials to use” )][System.Management.Automation.PSCredential] $credential = $null
)
PROCESS {
# Get the pointer to the provider for the site code
if ($siteCode -eq $null -or $siteCode -eq “”) {
Write-Verbose “Getting provider location for default site on server $HostName”
if ($credential -eq $null) {
$sccmProviderLocation = Get-WmiObject -query “select * from SMS_ProviderLocation where ProviderForLocalSite = true” -Namespace “rootsms” -computername $HostName -errorAction Stop
} else {
$sccmProviderLocation = Get-WmiObject -query “select * from SMS_ProviderLocation where ProviderForLocalSite = true” -Namespace “rootsms” -computername $HostName -credential $credential -errorAction Stop
}
} else {
Write-Verbose “Getting provider location for site $siteCode on server $HostName”
if ($credential -eq $null) {
$sccmProviderLocation = Get-WmiObject -query “SELECT * FROM SMS_ProviderLocation where SiteCode = ‘$siteCode'” -Namespace “rootsms” -computername $HostName -errorAction Stop
} else {
$sccmProviderLocation = Get-WmiObject -query “SELECT * FROM SMS_ProviderLocation where SiteCode = ‘$siteCode'” -Namespace “rootsms” -computername $HostName -credential $credential -errorAction Stop
}
}
# Split up the namespace path
$parts = $sccmProviderLocation.NamespacePath -split “”, 4
Write-Verbose “Provider is located on $($sccmProviderLocation.Machine) in namespace $($parts[3])”
# Create a new object with information
$retObj = New-Object -TypeName System.Object
$retObj | add-Member -memberType NoteProperty -name Machine -Value $HostName
$retObj | add-Member -memberType NoteProperty -name Namespace -Value $parts[3]
$retObj | add-Member -memberType NoteProperty -name SccmProvider -Value $sccmProviderLocation
return $retObj
}
}
Function Get-SCCMObject {
# Generic query tool
[CmdletBinding()]
PARAM (
[Parameter(Mandatory=$true, HelpMessage=“SCCM Server”,ValueFromPipelineByPropertyName=$true)][Alias(“Server”,“SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$true, HelpMessage=“SCCM Class to query”,ValueFromPipeline=$true)][Alias(“Table”,“View”)][String] $class,
[Parameter(Mandatory=$false,HelpMessage=“Optional Filter on query”)][String] $Filter = $null
)
PROCESS {
if ($Filter -eq $null -or $Filter -eq “”)
{
Write-Verbose “WMI Query: SELECT * FROM $class”
$retObj = get-wmiobject -class $class -computername $SccmServer.Machine -namespace $SccmServer.Namespace
}
else
{
Write-Verbose “WMI Query: SELECT * FROM $class WHERE $Filter”
$retObj = get-wmiobject -query “SELECT * FROM $class WHERE $Filter” -computername $SccmServer.Machine -namespace $SccmServer.Namespace
}
return $retObj
}
}
# – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#endregion
# – —Software Updates- – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
#Region Software Updates
# – – – – – – – – – – Software update – – – – – – – – – – – – – – –
Function Get-SCCMSoftwareUpdate {
<#
.SYNOPSIS
Returns the software update
.DESCRIPTION
Returns the existing software updates
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Get-SCCMSoftwareUpdate -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=“SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,“SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=“Search for a specific update based on the CI_UniqueID”)][String]$CI_UniqueID = $null,
[Parameter(Mandatory=$false, HelpMessage=“Search for a specific update based on the CI_ID”)][Int32]$CI_ID = $null,
[Parameter(Mandatory=$false, HelpMessage=“Search for a specific update based on the ArticleID”)][String]$ArticleID = $null,
[Parameter(Mandatory=$false, HelpMessage=“Search for a specific update based on the BulletinID”)][String]$BulletinID = $null,
[Parameter(Mandatory=$false, HelpMessage=“Optional Filter on query”)][String] $Filter = $null
)
begin{
Write-Verbose “Starting Software update process”
}
Process{
switch ($PSBoundParameters.keys){
(“CI_UniqueID”){ $Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdate” -Filter “CI_UniqueID=’$CI_UniqueID'”; break}
(“CI_ID”){$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdate” -Filter “CI_ID=’$CI_ID'” ; break}
(“ArticleID”){$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdate” -Filter “ArticleID=’$ArticleID'” ; break}
(“BulletinID”){$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdate” -Filter “BulletinID=’$BulletinID'” ; break}
Default {$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdate” -Filter $filter}
}
}
end{
Write-Verbose “Returning $($result)”
return $Result
}
}
# – – – – – – – – – – Software update Packages – – – – – – – – – – – – – – –
Function Get-SCCMSoftwareUpdatePackage {
<#
.SYNOPSIS
Returns the software update packages.
.DESCRIPTION
Queries for the software update packages.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
Get-SccmSoftwareUpdatesGroup -SccmServer $connection -Filter “Name= ‘Windows Server 2012 Software Updates'”
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=“SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,“SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=“Search for software update package based on name.”)][String] $Name = $null,
[Parameter(Mandatory=$false, HelpMessage=“Search for software update package based on PackageID”)][String] $PackageID = $null,
[Parameter(Mandatory=$false, HelpMessage=“Optional Filter on query”)][String] $Filter = $null
)
begin{
}
Process{
if ($name){
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdatesPackage” -Filter “Name=’$name'”
}
elseif($PackageID) {
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdatesPackage” -Filter “PackageID=’$PackageID'”
}
else{
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdatesPackage” -Filter $Filter
}
}
end{
return $Result
}
}
Function New-SCCMSoftwareUpdatePackage {
<#
.SYNOPSIS
Creates a software update package
.DESCRIPTION
Creates a software update package. Need an UNC Path.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
New-SCCMSoftwareUpdatePackage -name “Test” -description “test2” -PackageSourcePath “cbd05repositorySoftware PackagesSoftware UpdatesTest” -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=“SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,“SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=“Insert Site code”)][String]$SiteCode,
[Parameter(Mandatory=$true, HelpMessage=“Input a valid UNC Path”)][String]$PackageSourcePath,
[Parameter(Mandatory=$true, HelpMessage=“Input a valid name”)][String]$Name,
[Parameter(Mandatory=$false, HelpMessage=“Input a valid description”)][String]$Description,
[Parameter(Mandatory=$false, HelpMessage=“PackageSourceFlag”)][String]$PackageSourceFlag
)
begin{
write-verbose “Starting Software update Package creation”
}
Process{
If (!($siteCode)){
$siteCode = $sccmServer.SccmProvider.SiteCode
}
$WMI_SoftwareUpdatesPackage = [wmiclass]“$($sccmServer.machine)$($sccmServer.Namespace):SMS_SoftwareUpdatesPackage”
$NewInstance = $WMI_SoftwareUpdatesPackage.createInstance()
$NewInstance.name = $Name
$NewInstance.SourceSite = $siteCode
$NewInstance.PkgSourcePath = $PackageSourcePath
$NewInstance.PkgSourceFlag= $PackageSourceFlag
$NewInstance.description = $Description
$NewInstance.put() | Out-Null
$NewInstance.get
}
end{
return $NewInstance
}
}
Function Remove-SCCMSoftwareUpdatePackage {
<#
.SYNOPSIS
Deletes a Software update Package
.DESCRIPTION
Deletes the software update Pacakge from SCCM (It doesn‘t delete the sources).
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Get-SCCMSoftwareUpdatelist -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Deletes a specific Software Update package based on the Name”)][String]$Name = $null,
[Parameter(Mandatory=$false, HelpMessage=”Deletes a specific Software Update package based on the Package”)][String]$PackageID = $null
)
begin{
Write-Verbose “Starting Getting software update list process.”
}
Process{
If ($PackageID){$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -PackageID $PackageID}
elseif ($name){$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -Name $name}
if ($UpdatePackage){
Write-Verbose “Deleting UpdateList : $($UpdatePackage.LocalizedDisplayName).”
$UpdatePackage.delete()
}
}
end{}
}
Function Add-SCCMSoftwareUpdateToSoftwareUpdatePackage {
<#
.SYNOPSIS
Creates a software update package
.DESCRIPTION
Creates a software update package. Need an UNC Path.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Insert a CI_ID of the Update (Do not use in conjunction with ArticleID, or CI_UniqueID”)][String]$CI_ID,
[Parameter(Mandatory=$false, HelpMessage=”Insert a CI_UniqueID of the Update (Do not use in conjunction with ArticleID or CI_ID”)][String]$CI_UniqueID,
[Parameter(Mandatory=$false, HelpMessage=”Insert the ArticleID of the Update (Do not use in conjunction with CI_ID or CI_UniqueID)”)][String]$ArticleID,
[Parameter(Mandatory=$true, HelpMessage=”Input temporary UNC Path”)][String]$TemporaryPath,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid Package name”)][String]$PackageName,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid PackageID”)][String]$UpdatePackageID
#[Parameter(Mandatory=$false, HelpMessage=”An array of CI_IDs of the software updates”)][Array]$Updates
)
begin{
write-verbose “Starting to updates to Software update Package $($name)”
}
Process{
$AllContentIDs = @()
$ContentID = @()
$ContentPath = @()
if ($PackageName){
$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -Name $PackageName
}
elseif($UpdatePackageID){
$updatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -PackageID $UpdatePackageID
}
if (!($updatePackage)){
Write-Warning “The update package could not be found. Verify the package exists and try again.”
break
}else{
Write-Verbose “The update package $($updatePackage.name) with ID: $($updatePackage.PAckageID) has been found.”
}
If ($ArticleID){
$UpdateInfo = Get-SCCMSoftwareUpdate -SccmServer $SccmServer -ArticleID $ArticleID
$CiUniqueID = $UpdateInfo.CI_UniqueID
$CI_ID = $UpdateInfo.CI_ID
}elseif ($CI_ID){
$CiUniqueID = (Get-SCCMSoftwareUpdate -SccmServer $SccmServer -CI_ID $CI_ID).Ci_UniqueID
}
elseif($CI_UniqueID){
$CI_ID = (Get-SCCMSoftwareUpdate -SccmServer $SccmServer -CI_UniqueID $CI_UniqueID).CI_ID
}
##To check
$ContentIDs = Get-SCCMObject -sccmServer $SccmServer -class “SMS_CIToContent” -Filter “CI_ID=’$CI_ID‘”
forEach($contentID in $ContentIDs){
write-verbose “Working on $($contentID)”
$ContentIDnumber = $ContentID.ContentID
write-verbose “ContentIDnumber = $ContentIDnumber”
$ContentFile = Get-SCCMObject -sccmServer $SccmServer -class “SMS_CIContentFiles” -Filter “ContentID=’$ContentIDnumber‘”
$downloadUrl = $ContentFile.SourceUrl
$Filename = $ContentFile.filename
$DestinationFolder = Join-Path -path $TemporaryPath -ChildPath $CiUniqueID
if (!(Test-Path $DestinationFolder)){
mkdir $DestinationFolder | Out-Null
}
$destination = Join-Path -Path $DestinationFolder -ChildPath $Filename
Write-Verbose “Launching the download of CI_ID: $($CI_ID) from link: $($downloadUrl) to $($destination)”
$wc = New-Object System.Net.WebClient
#Import-Module bitsTransfer
try{
#start-bitsTransfer -Source $downloadUrl -Destination $destination
$wc.DownloadFile($downloadUrl, $destination)
}
catch{
$_.exception.message
}
$AllContentIDs += $ContentIDnumber
$ContentPath += “$DestinationFolder”
}
#$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -Name $Name
$UpdatePackage = gwmi -Class SMS_SoftwareUpdatesPackage -computer $sccmServer.machine -namespace $sccmServer.namespace -Filter “Name = ‘$($updatePackage.name)‘”
$UpdatePackageLazy = [WMI]$UpdatePackage.__PATH
$UpdatePackageLazy.AddupdateContent($AllContentIDs,$ContentPath,$true) | out-null
#Deleting temporary folder
Remove-Item “$($DestinationFolder)” -Recurse
}
End{
return $UpdatePackageLazy
}
}
Function Remove-SCCMSoftwareUpdateFromSoftwareUpdatePackage {
<#
.SYNOPSIS
Removes a software update package
.DESCRIPTION
Creates a software update package. Need an UNC Path.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Insert a CI_ID of the Update (Do not use in conjunction with ArticleID, or CI_UniqueID”)][String]$CI_ID,
[Parameter(Mandatory=$false, HelpMessage=”Insert a CI_UniqueID of the Update (Do not use in conjunction with ArticleID or CI_ID”)][String]$CI_UniqueID,
[Parameter(Mandatory=$false, HelpMessage=”Insert the ArticleID of the Update (Do not use in conjunction with CI_ID or CI_UniqueID)”)][String]$ArticleID,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid Package name”)][String]$PackageName,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid PackageID”)][String]$UpdatePackageID
#[Parameter(Mandatory=$false, HelpMessage=”An array of CI_IDs of the software updates”)][Array]$Updates
)
begin{
write-verbose “Starting to remove updates from Software update Package $($name)”
}
Process{
$ContentID = @()
$ContentPath = @()
if ($PackageName){
$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -Name $PackageName
}
elseif($UpdatePackageID){
$updatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -PackageID $UpdatePackageID
}
if (!($updatePackage)){
Write-Warning “The update package could not be found. Verify the package exists and try again.”
break
}else{
Write-Verbose “The update package $($updatePackage.name) with ID: $($updatePackage.PAckageID) has been found.”
}
If ($ArticleID){
$UpdateInfo = Get-SCCMSoftwareUpdate -SccmServer $SccmServer -ArticleID $ArticleID
$CiUniqueID = $UpdateInfo.CI_UniqueID
$CI_ID = $UpdateInfo.CI_ID
}elseif ($CI_ID){
$CiUniqueID = (Get-SCCMSoftwareUpdate -SccmServer $SccmServer -CI_ID $CI_ID).Ci_UniqueID
}
elseif($CI_UniqueID){
$CI_ID = (Get-SCCMSoftwareUpdate -SccmServer $SccmServer -CI_UniqueID $CI_UniqueID).CI_ID
}
$ContentID = (Get-SCCMObject -sccmServer $SccmServer -class “SMS_CIToContent” -Filter “CI_ID=’$CI_ID‘”).ContentID
#$UpdatePackage = Get-SCCMSoftwareUpdatePackage -SccmServer $sccmServer -Name $Name
#$UpdatePackage
$UpdatePackage = gwmi -Class SMS_SoftwareUpdatesPackage -computer $sccmServer.machine -namespace $sccmServer.namespace -Filter “Name = ‘$($updatePackage.name)‘”
$UpdatePackageLazy = [WMI]$UpdatePackage.__PATH
#Removing update from softwareupdate package
#http://msdn.microsoft.com/en-us/library/cc144265.aspx
$UpdatePackageLazy.RemoveContent($ContentID,$false) | out-null
}
End{
return $UpdatePackageLazy
}
}
Function Get-SCCMSoftwareUpdatesPackageSourcePath {
<#
.SYNOPSIS
NOT WORKING YET !!!
.DESCRIPTION
Queries for the software update packages
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
Get-SccmSoftwareUpdatesGroup -SccmServer $connection -Filter “Name= ‘Windows Server 2012 Software Updates‘”
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Optional Filter on query”)][String] $Filter = $null
)
begin{
}
Process{}
end{
return Get-SCCMObject -sccmServer $SccmServer -class “SMS_SoftwareUpdatesPackage” -Filter $Filter
}
}
# – – – – – – – – – – Software update lists – – – – – – – – – – – – – – –
Function Get-SCCMSoftwareUpdateList {
<#
.SYNOPSIS
Returns the software update lists
.DESCRIPTION
Returns the existing software updates lists in SCCM
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.PARAMETER Full
Returns all the properties of the software update list.
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Get-SCCMSoftwareUpdatelist -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Optional Filter on query”)][String] $Filter = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update List based on the Name”)][String]$Name = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update List based on the CI_ID”)][Int32]$CI_ID = $null,
[Parameter(Mandatory=$false, HelpMessage=”Will get all the properties (impacts performance)”)][switch]$Full #Only use if really needed.
)
begin{
Write-Verbose “Starting Getting software update list process.”
}
Process{
if($Name){
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_AuthorizationList” -Filter “LocalizedDisplayName=’$Name‘”
if ($Full){
Write-verbose “Full Activated. Returning lazy properties. This might Impact performance !”
[WMI]$Result = $Result.__Path
}
else{
}
}
elseif($CI_ID){
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_AuthorizationList” -Filter “CI_ID=’$CI_ID‘”
if ($Full){
Write-verbose “Full Activated. Returning lazy properties. This might Impact performance !”
[WMI]$Result = $Result.__Path
}
else{
}
}
else {
Write-Verbose “No parameters.”
if ($Full){
Write-verbose “Full Activated. Returning all the properties. This might Impact performance !”
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_AuthorizationList” -Filter $filter
#Lazy properties needs to be fetch individually…
If ($Result.count -ge 2){
$Temp = @()
foreach ($res in $Result){
$Temp += [WMI]$res.__Path
}
$result = $Temp
}
else{
[WMI]$Result = $Result.__Path
}
}
else{
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_AuthorizationList” -Filter $filter
}
}#Endelse
}
end {
Write-Verbose “Returning $($result)”
return $result
}
}
Function Update-SCCMSoftwareUpdateList {
<#
.SYNOPSIS
Updates an already existing software update lists
.DESCRIPTION
Updates an already existing software update lists based on the CI_ID of the software update list.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer.
.PARAMETER Name
Name for the Software update list.
.PARAMETER Description
Description for the Software update list.
.PARAMETER Updates
An array of CI_ID updates that need to be added to the software update list.
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Update-SCCMSoftwareUpdateList -SccmServer $connection -CI_ID 151 -Name “Updated update list” -Description “New Update list discription” -updates 114
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$true, HelpMessage=”Input a valid name”)][String]$Name,
[Parameter(Mandatory=$true, HelpMessage=”Software update list CI_ID”)][String]$CI_ID,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid description”)][String]$Description,
[Parameter(Mandatory=$false, HelpMessage=”Collection of Update CI_IDs”)][Array]$Updates
)
begin{}
Process{
if ($CI_ID){
$UpdateList = Get-SCCMSoftwareUpdateList -SccmServer $sccmServer -CI_ID $CI_ID -Full
}
else{
Write-Verbose “Neither a name or a CI_ID has been given to identify the correct Software update list. Returning null.”
}
$WMI_LocalizedProperties = [wmiclass]”$($connection.machine)$($connection.Namespace):SMS_CI_LocalizedProperties”
$WMI_LocalizedProperties_Instance=$WMI_LocalizedProperties.createInstance()
$WMI_LocalizedProperties_Instance.Displayname = $Name
$WMI_LocalizedProperties_Instance.Description = $Description
$UpdateList.localizedinformation = $WMI_LocalizedProperties_Instance
$UpdateList.updates += $updates
$UpdateList.put()
}
End{}
}
Function New-SCCMSoftwareUpdateList {
<#
.SYNOPSIS
Creates a new software update lists
.DESCRIPTION
Creates a new Software update list from scratch.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer.
.PARAMETER Name
Name for the new Software update list.
.PARAMETER Description
Description for the new Software update list.
.PARAMETER Updates
An array of CI_ID updates.
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
New-SCCMSoftwareUpdatelist -SccmServer $connection -name “New SUP List” -Description “This is the description” -Updates $ArrayOfCI_IDs
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer,hostname”)][System.Object] $SccmServer,
[Parameter(Mandatory=$true, HelpMessage=”Input a valid name”)][String]$Name,
[Parameter(Mandatory=$false, HelpMessage=”Input a valid description”)][String]$Description,
[Parameter(Mandatory=$false, HelpMessage=”Collection of Update CI_IDs”)][Array]$Updates
)
$WMI_SoftwareUpdatesList = [wmiclass]”$($sccmServer.machine)$($sccmServer.Namespace):SMS_AuthorizationList”
$SoftwareUpdatesList_Instance = $WMI_SoftwareUpdatesList.createInstance()
#Creating Information Object
$WMI_LocalizedProperties = [wmiclass]”$($SccmServer.machine)$($SccmServer.Namespace):SMS_CI_LocalizedProperties”
$WMI_LocalizedProperties_Instance=$WMI_LocalizedProperties.createInstance()
$WMI_LocalizedProperties_Instance.Displayname = $Name
$WMI_LocalizedProperties_Instance.Description = $Description
$SoftwareUpdatesList_Instance.localizedinformation = $WMI_LocalizedProperties_Instance
If ($updates){
#An array of updates CI_IDs is needed.
$SoftwareUpdatesList_Instance.updates = $updates
}
$SoftwareUpdatesList_Instance.put()
}
Function Remove-SCCMSoftwareUpdateList {
<#
.SYNOPSIS
Deletes a Software update list
.DESCRIPTION
Deletes the software update list from SCCM
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Remove-SCCMSoftwareUpdatelist -SccmServer $connection -name “Windows Server 2003 Update List”
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update List based on the Name”)][String]$Name = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update List based on the CI_ID”)][Int32]$CI_ID = $null
)
begin{
Write-Verbose “Starting Getting software update list process.”
}
Process{
If ($CI_ID){$UpdateList = Get-SCCMSoftwareUpdateList -SccmServer $sccmServer -CI_ID $CI_ID}
elseif ($name){$UpdateList = Get-SCCMSoftwareUpdateList -SccmServer $sccmServer -Name $name}
Write-Verbose “Update list : $($UpdateList)”
if ($updateList){
Write-Verbose “Deleting UpdateList : $($updatelist.LocalizedDisplayName) .”
$updateList.delete()
}
}
}
#—- Software update Deployments——-
Function Get-SCCMSoftwareUpdateDeployment {
<#
.SYNOPSIS
Returns the software update deployments
.DESCRIPTION
Returns the existing software updates deployments in SCCM
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01”
Get-SCCMSoftwareUpdateDeployment -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server”,ValueFromPipeline=$true)][Alias(“Server”,”SmsServer”)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Optional Filter on query”)][String] $Filter = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update deployment based on the Name”)][String]$Name = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update deployment based on the AssignmentID”)][String]$DeploymentID = $null,
[Parameter(Mandatory=$false, HelpMessage=”Will get all the lazy properties (impacts performance !)”)][switch]$Full #Only use if really needed.
)
begin{
Write-Verbose “Starting Getting software update list process.”
}
Process{
#SMS_UpdatesAssignment has lazy properties !
switch ($PSBoundParameters.values){
($Name){$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_UpdatesAssignment” -Filter “AssignmentName=’$Name‘”
if ($Full){
Write-verbose “Full Activated. Returning lazy properties. This might Impact performance !”
[WMI]$Result = $Result.__Path
break
}
else{
Break
}
}
($DeploymentID){
$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_UpdatesAssignment” -Filter “AssignmentID=’$DeploymentID‘“
if ($Full){
Write-verbose “Full Activated. Returning lazy properties. This might Impact performance !“
[WMI]$Result = $Result.__Path
break
}
else{
Break
}
}
default {$Result = Get-SCCMObject -sccmServer $SccmServer -class “SMS_UpdatesAssignment” -Filter $Filter}
}#End of switch
}#End of process block
End{
Return $Result
}
}
Function New-SCCMSoftwareUpdateDeployment {
<#
.SYNOPSIS
Creates a new Software Update deployment
.DESCRIPTION
Creates a new Software Update deployment
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01“
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server“,ValueFromPipeline=$true)][Alias(“Server“,”SmsServer“)][System.Object] $SccmServer,
[Parameter(Mandatory=$True, HelpMessage=”Name for the Software Update deployment“)][String]$Name,
[Parameter(Mandatory=$false, HelpMessage=”Name for the Software Update deployment description“)][String]$Description,
[Parameter(Mandatory=$True, HelpMessage=”Collection where to deploy the Software Updates“)][String]$CollectionID,
[Parameter(Mandatory=$true, HelpMessage=”Array of CI_IDs that need to be deployed.“)][Array]$Updates,
[Parameter(Mandatory=$true, HelpMessage=”YYYYMMDDhhmm“)][string]$StartTime,
[Parameter(Mandatory=$true, HelpMessage=”YYYYMMDDhhmm“)][string]$EnforcementDeadline,
[Parameter(Mandatory=$true, HelpMessage=”Suppress reboots.“)]$SuppressReboot,
[Parameter(Mandatory=$true, HelpMessage=”Switch to apply to subTargets or not.“)][bool]$ApplyToSubTargets, #Bool
[Parameter(Mandatory=$true, HelpMessage=”Default is to apply“)][int]$AssignmentAction,
[Parameter(Mandatory=$true, HelpMessage=”Log compliance to Windows event. “)][bool]$LogComplianceToWinEvent, #bool
[Parameter(Mandatory=$true, HelpMessage=”Notify user of new updates availability.“)][bool]$NotifyUser, #Bool
[Parameter(Mandatory=$false, HelpMessage=”Activate SCOM alerts on failure.“)][bool]$ActivateScomAlertsOnFailure,#bool
[Parameter(Mandatory=$false, HelpMessage=”Deployment is read only. Default is False.“)][bool]$ReadOnly, #bool
[Parameter(Mandatory=$false, HelpMessage=”Send detailed compliance status. “)][bool]$SendDetailedNonComplianceStatus,
[Parameter(Mandatory=$false, HelpMessage=”Use UTC time.Default is local user time.“)]$UTCtime,
[Parameter(Mandatory=$false, HelpMessage=”The LocaledID“)]$LocaleID,
[Parameter(Mandatory=$false, HelpMessage=”the desired config type.1 = Required, 2= Not Allowed“)]$DesiredConfigType,
[Parameter(Mandatory=$false, HelpMessage=”The DPLocality can be: 4 = DP_DOWNLOAD_FROM_LOCAL, 6 = DP_DOWNLOAD_FROM_REMOTE,17 = DP_NO_FALLBACK_UNPROTECTED “)]$DPLocality
)
begin{
Write-Verbose “Starting Getting software update list process.“
}
Process{
$WMI_SoftwareUpdatesAssignment = [wmiclass]”$($sccmServer.machine)$($sccmServer.Namespace):SMS_UpdatesAssignment“
Write-Verbose “creating new instance“
$NewSoftwareUpdateAssignment = $WMI_SoftwareUpdatesAssignment.CreateInstance()
$NewSoftwareUpdateAssignment.AssignmentName = $name
$NewSoftwareUpdateAssignment.AssignmentDescription = $Description
$NewSoftwareUpdateAssignment.TargetCollectionID = $CollectionID
$NewSoftwareUpdateAssignment.AssignedCIs = $Updates
#true to apply the configuration item assignment to a subcollection.
$NewSoftwareUpdateAssignment.ApplyToSubTargets = $ApplyToSubTargets
#Assignment Action: 1 = Detect , 2= Apply (2= default)
switch ($AssignmentAction){
(“Detect“) {$NewSoftwareUpdateAssignment.AssignmentAction = 1}
(“Apply“) {$NewSoftwareUpdateAssignment.AssignmentAction = 2}
default {$NewSoftwareUpdateAssignment.AssignmentAction = $AssignmentAction}
}
#DesiredConfigType : 1 Required, 2= Not Allowed (1= default)
$NewSoftwareUpdateAssignment.DesiredConfigType = $DesiredConfigType
#4 DP_DOWNLOAD_FROM_LOCAL, 6 DP_DOWNLOAD_FROM_REMOTE,17 DP_NO_FALLBACK_UNPROTECTED
$NewSoftwareUpdateAssignment.DPLocality = $DPLocality
$NewSoftwareUpdateAssignment.LocaleID = $LocaleID
$NewSoftwareUpdateAssignment.LogComplianceToWinEvent = $LogComplianceToWinEvent
$NewSoftwareUpdateAssignment.NotifyUser = $NotifyUser
$NewSoftwareUpdateAssignment.RaiseMomAlertsOnFailure = $ActivateScomAlertsOnFailure
$NewSoftwareUpdateAssignment.ReadOnly = $ReadOnly
$NewSoftwareUpdateAssignment.StartTime = $StartTime #+ “00.000000+***” #YYYYMMDDhhmm #String is needed
$NewSoftwareUpdateAssignment.EnforcementDeadline = $EnforcementDeadline #+ “00.000000+***” #YYYYMMDDhhmm #String is needed
$NewSoftwareUpdateAssignment.SuppressReboot = $SuppressReboot
$NewSoftwareUpdateAssignment.UseGMTTimes = $UTCtime
$NewSoftwareUpdateAssignment.SendDetailedNonComplianceStatus = $SendDetailedNonComplianceStatus
$NewSoftwareUpdateAssignment.put()
}
End{}
}
Function Remove-SCCMSoftwareUpdateDeployment {
<#
.SYNOPSIS
Removes a Software update deployment.
.DESCRIPTION
Deletes the software update deployment from the SCCM server permantly.
.PARAMETER SccmServer
Sccm Connection object created with Connect-SccmServer
.PARAMETER DeploymentID
Deletes a software update deployment according to the DeploymentID.
.PARAMETER Name
Deletes a software update deployment according to his name.
.EXAMPLE
$Connect-SccmServer = -SccmServer “MyServer01“
Get-SCCMSoftwareUpdatelist -SccmServer $connection
.NOTES
Author: Stéphane van Gulick
version: 1.0
History:
.LINK
www.PowerShellDistrict.com
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, HelpMessage=”SCCM Server“,ValueFromPipeline=$true)][Alias(“Server“,”SmsServer“)][System.Object] $SccmServer,
[Parameter(Mandatory=$false, HelpMessage=”Optional Filter on query“)][String] $Filter = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update deployment based on the Name“)][String]$Name = $null,
[Parameter(Mandatory=$false, HelpMessage=”Search for a specific Software Update deployment based on the AssignmentID“)][String]$DeploymentID = $null,
[Parameter(Mandatory=$false, HelpMessage=”Will get all the lazy properties (impacts performance !)“)][switch]$Full #Only use if really needed.
)
begin{
Write-Verbose “Starting Getting software update list process.“
}
Process{
If ($Name){
$SoftwareUpdateDeployment = Get-SCCMSoftwareUpdateDeployment -SccmServer $SccmServer -Name $Name
}
elseif($DeploymentID){
$SoftwareUpdateDeployment = Get-SCCMSoftwareUpdateDeployment -SccmServer $SccmServer -deploymentID $DeploymentID
}
else{
$SoftwareUpdateDeployment = Get-SCCMSoftwareUpdateDeployment -SccmServer $SccmServer -filter $filter
}
}
end{
Write-Verbose “Attempting to delete : $($SoftwareUpdateDeployment.AssignmentName).“
$SoftwareUpdateDeployment.Delete()
}
}
#EndRegion
|
Leave A Comment