Parameter splatting supplies a command with a collection of parameter names and values. Build a hash table, use parameter names as keys, and pass the table with @ instead of $. section 12.1
Use splatting to make day-to-day automation easier to maintain:
- Put each parameter on its own line so command configuration is easier to read and stays within a practical code width. section 12.1
- Represent switch parameters with $True, just as with the Verbose parameter. section 12.1
- Reuse and modify parameter tables when several calls share options or when a query changes by selected data type. section 18.14
- Prefer splatting over repeated command text when repetition makes scripts cumbersome; cleaner code is easier to read and debug. section 18.14
A CIM query with named parameters
Store ClassName and ComputerName in $params, then invoke Get-CimInstance @params. Add Verbose=$True when the command needs that switch. The same pattern supports session-based queries by storing CimSession, filters, or other values in separate parameter tables. section 12.1
A reusable query pattern
Start with a ComputerName entry, add a ClassName entry inside a Switch branch for OS, CS, CPU, or Memory, then splat the completed table into Get-CimInstance. Build the property list alongside it and pass that list to Select-Object. section 18.14
$params = @{'ClassName'='Win32_OperatingSystem'
'ComputerName'='CLIENT1'}
Inspect the compact progression from constructing a parameter table to invoking a command with splatting. section 12.1
