Monday, July 3, 2017

SCOM: Using [bracket] NoteProperties in PowerShell

What are those brackets [] in PowerShell!!?? When you query class instances, you'll see a numer of properties available of the type 'NoteProperty'. Direct or inherited from parent classes. To use or filter on these class instance properties in PowerShell, you need to use a specific syntax.

 You either enclose with single quotes or escape with backtick. In this example i'm using an instance of the 'Windows Server' class from one of the default SCOM management packs. This class inherits the property 'IPAddress' from the base class 'Windows Computer'.

 Here are the useable options for PowerShell:
#Get all available properties
Get-SCOMClass -DisplayName "Windows Server" | Get-SCOMClassInstance | Get-Member
...
[Microsoft.Windows.Computer].ActiveDirectoryObjectSid
[Microsoft.Windows.Computer].ActiveDirectorySite
[Microsoft.Windows.Computer].DNSName
[Microsoft.Windows.Computer].DomainDnsName
[Microsoft.Windows.Computer].ForestDnsName
[Microsoft.Windows.Computer].HostServerName
[Microsoft.Windows.Computer].IPAddress
[Microsoft.Windows.Computer].IsVirtualMachine
[Microsoft.Windows.Computer].LastInventoryDate
[Microsoft.Windows.Computer].LogicalProcessors
[Microsoft.Windows.Computer].NetbiosComputerName
[Microsoft.Windows.Computer].NetbiosDomainName
[Microsoft.Windows.Computer].NetworkName
[Microsoft.Windows.Computer].OffsetInMinuteFromGreenwichTime
[Microsoft.Windows.Computer].OrganizationalUnit
[Microsoft.Windows.Computer].PhysicalProcessors
[Microsoft.Windows.Computer].PrincipalName
[Microsoft.Windows.Computer].VirtualMachineName
...

#
# Using a NoteProperty
# ** Where-Object / ForEach-Object clause **

{ $_.'[Microsoft.Windows.Computer].IPAddress'.Value }

# ** Select-Object **
Select-Object ``[Microsoft.Windows.Computer`].IPAddress
Select-Object *.IPAddress

# ** Change column name or object property name **
# Looks like the syntax for Where-Object, but 'Value' subproperty is not specified!
Select-Object @{Expression={$_.'[Microsoft.Windows.Computer].IPAddress'};Label="IP"}

0 reacties:

Post a Comment