1

I am trying to let PowerShell filter a number of objects from a cmdlet and pick an object that has a specific name format.

The name format is always going to be same like below: current Month Name + Year + Workstations

For example the format for current month looks like below: August 2021 Workstations

I tried the below but didn't succeed getting the desired output.

$currentMonth = 
    (Get-UICulture).DateTimeFormat.GetMonthName((Get-Date).Month.ToString())
$LatestSUG = 
    Get-CMSoftwareUpdateGroup | 
        Select-Object LocalizedDisplayName  | 
            Where-Object -Property LocalizedDisplayName -EQ '$currentMonth'

The cmdlet is Get-CMSoftwareUpdateGroup The object name I am trying to filter is LocalizedDisplayName

Thanks very much for any help on this.

Olaf
  • 4,690
  • 2
  • 15
  • 23
Mark
  • 13
  • 3

2 Answers2

1

Try removing the single quote around $currentMonth and see if that works better for you.

$currentMonth = (Get-UICulture).DateTimeFormat.GetMonthName((Get-Date).Month.ToString())
    
$LatestSUG = Get-CMSoftwareUpdateGroup | Select-Object LocalizedDisplayName | Where-Object -Property LocalizedDisplayName -match $currentMonth
notjustme
  • 2,376
  • 2
  • 20
  • 27
0

Instead for equality you should check if the LocalizedDisplayName matches the $CurrentMonth ... like this maybe:

$currentMonth = 
    (Get-UICulture).DateTimeFormat.GetMonthName((Get-Date).Month.ToString())
$LatestSUG = 
    Get-CMSoftwareUpdateGroup | 
        Where-Object -Property LocalizedDisplayName -Match $currentMonth
Olaf
  • 4,690
  • 2
  • 15
  • 23
  • Thanks for taking time to look into this question. It helped ! Sorry I came back late. – Mark Aug 26 '21 at 03:08