Created
November 24, 2025 20:07
-
-
Save MyITGuy/5bb25ae06b75cb0393bb3081732cbe9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #region Get-SMSAdvertisement | |
| function Get-SMSAdvertisement { | |
| [CmdletBinding()] | |
| PARAM( | |
| [Alias('PKG_PackageID')] | |
| [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
| [string] | |
| $PackageId | |
| , | |
| [Alias('PRG_ProgramName')] | |
| [Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
| [string] | |
| $ProgramName | |
| , | |
| [Alias('ADV_AdvertisementID')] | |
| [Parameter(Mandatory = $false, Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
| [string] | |
| $AdvertisementId | |
| ) | |
| begin { | |
| Write-Verbose $MyInvocation.MyCommand | |
| filter filterByPackageId { | |
| $Object = $_ | |
| if ($PackageId) { | |
| $Object | Where-Object PKG_PackageID -eq $PackageId | |
| } | |
| else { | |
| $Object | |
| } | |
| } | |
| filter filterByProgramName { | |
| $Object = $_ | |
| if ($ProgramName) { | |
| $Object | Where-Object PRG_ProgramName -eq $ProgramName | |
| } | |
| else { | |
| $Object | |
| } | |
| } | |
| filter filterByAdvertisementId { | |
| $Object = $_ | |
| if ($AdvertisementId) { | |
| $Object | Where-Object ADV_AdvertisementID -eq $AdvertisementId | |
| } | |
| else { | |
| $Object | |
| } | |
| } | |
| } | |
| process { | |
| try { | |
| Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0, $Env:SMS_ADMIN_UI_PATH.Length - 5) + '\ConfigurationManager.psd1') | |
| $SiteCode = (Get-CimInstance -ClassName __NAMESPACE -Namespace "root\sms" | Select-Object -ExpandProperty Name).Substring(5, 3) | |
| if ((Get-PSDrive -Name $SiteCode) -isnot [Microsoft.ConfigurationManagement.PowerShell.Provider.CMDriveInfo]) { | |
| New-PSDrive -Name $SiteCode -PSProvider "AdminUI.PS.Provider\CMSite" -Root ([System.Net.Dns]::GetHostByName(($env:computerName))).Hostname -Description "$($SiteCode) Primary Site" | |
| } | |
| Push-Location -Path "$($SiteCode):" | |
| # Execute on any computer with CM client | |
| # Get CCM_SoftwareDistribution for reading | |
| Get-CimInstance -ClassName "SMS_Advertisement" -Namespace "root\sms\site_$SiteCode" | filterByPackageId | filterByProgramName | filterByAdvertisementId | |
| } | |
| catch { | |
| Throw $_ | |
| } | |
| } | |
| end { | |
| Pop-Location | |
| } | |
| } | |
| #endregion Get-SMSAdvertisement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment