Monday, December 18, 2017

SCCM: Query collection membership for specific system

Beneath you find a WQL query for listing all collection memberships for a specific system in SCCM I got some examples of the internet which didn't work for me. This query does and uses a prompt asking for a system resource name.
select COL.Name from SMS_Collection as COL
JOIN SMS_FullCollectionMembership as COLMEM on COL.CollectionID = COLMEM.CollectionID where COLMEM.Name = ##PRM:SMS_FullCollectionMembership.Name##
order by COL.Name
You can use this query within SCCM solely as a Query or as a collection membership query. For SQL queries and reports take a look here

Thursday, December 14, 2017

PowerShell: Encapsulate 64 bit cmdlet in a 32 bit context

Found a rather old but nice tip from Neil Peterson to tackle a challenge executing Powershell 64 bit cmdlets from a 32 bit execution context (Orchestrator in his example). Just wanted to share this and add it to my own blog for enhancing my toolbox.
#living in a 32 bit universe

#starting PowerShell 'sysnative' version and thus 64 bit
#more info: https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx

$ClusterNodes = .$env:windir\sysnative\WindowsPowerShell\v1.0\powershell.exe {

 #living in a 64 bit universe
 Get-ClusterNode -Cluster clustername

}

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"}