Lab/Demo: Using PowerShell pipeline (the first one)
Exercise 2: Filtering objects
Task 5: Create a report that displays specified Control Panel items
What is this trying to achieve? To list all the items in the System and Security category and in only that category. One item (Power Options) is in two categories, so it should be excluded.
Get-ControlPanelItem -Category "System and Security" `
| where { -not ($PSItem.Category -notlike "*System and Security*") } `
| sort name `
| ft name, category
Since the Category property is a collection (note the braces), there is a much better way of doing this - the Count property. This also avoids the use of a double negative, a frequent source of confusion.
Get-ControlPanelItem -Category "System and Security" `
| where { $PSItem.Category.count -eq 1 } `
| sort name `
| ft name, category
Note that Get-ControlPanelItem is not in PowerShell 7.
Lab/Demo: Using PowerShell pipeline (the first one)
Exercise 2: Filtering objects
Task 5: Create a report that displays specified Control Panel items
What is this trying to achieve? To list all the items in the System and Security category and in only that category. One item (Power Options) is in two categories, so it should be excluded.
Since the Category property is a collection (note the braces), there is a much better way of doing this - the Count property. This also avoids the use of a double negative, a frequent source of confusion.
Note that
Get-ControlPanelItem
is not in PowerShell 7.