# Use Get-ChildItem normally Get-ChildItem -Path C:\Windows\System32 -Filter *.ocx -File -Force -Attributes !Offline+!ReadOnly+!Hidden -Name # Re-format the Get-ChildItem parameters using backticks Get-ChildItem -Path C:\Windows\System32 ` -Filter *.ocx ` -File ` -Force ` -Attributes !Offline+!ReadOnly+!Hidden ` -Name # Store parameters in a string and execute using Invoke-Expression $System32String = "-Path C:\Windows\System32 -Filter *.ocx -File -Force -Attributes !Offline+!ReadOnly+!Hidden -Name" Invoke-Expression -Command "Get-ChildItem $System32String" # Execute Get-ChildItem using Splatting $System32Splat = @{ Path = 'C:\Windows\System32' Filter = '*.ocx' File = $true Force = $true Attributes = '!Offline+!ReadOnly+!Hidden' Name = $true } Get-ChildItem @System32Splat # View the contents and object type of the Hashtable $System32Splat $System32Splat.GetType() # Change the filter in the hashtable $System32Splat.Filter = '*.dll' $System32Splat Get-ChildItem @System32Splat # Remove the filter and add the parameter manually $System32Splat.Remove('Filter') Get-ChildItem @System32Splat -Filter *.ocx # Combine two separate hashtables and splat into the Cmdlet $System32OCXFilter = @{ Filter = '*.ocx' } Get-ChildItem @System32Splat @System32OCXFilter # Change the Attributes property and execute Get-Childitem $System32Splat.Attributes = '!Offline+!ReadOnly+Hidden' Get-ChildItem @System32Splat @System32OCXFilter # Example WMI query and the splat alternative Get-WmiObject -Namespace Root\Cimv2 -Class Win32_Service -ComputerName jbdc01.jb.com -Filter "Name = 'ADWS' OR Name = 'AeLookupSvc' OR Name = 'ALG'" -ErrorAction Stop $WMIService = @{ Namespace = 'Root\Cimv2' Class = 'Win32_Service' ComputerName = 'jbdc01.jb.com' Filter = "Name = 'ADWS' OR Name = 'AeLookupSvc' OR Name = 'ALG'" ErrorAction = 'Stop' } Get-WmiObject @WMIService # Function to demo the splatting functionality function Get-ComputerOS { param ( $ComputerName = $env:COMPUTERNAME, [switch]$DisplayAll, [switch]$DisplayOSName, [switch]$DisplayKernel ) # Setup Wmi Hashtable $WMIOS = @{ Namespace = 'Root\Cimv2' Class = 'Win32_OperatingSystem' ComputerName = 'jbdc01.jb.com' ErrorAction = 'Stop' } # Setup Select-Object Hashtable $SelectedProperty = @{} switch ($x) { {$DisplayAll} {[string[]]$SelectedProperty.Property += '*'} {$DisplayOSName} {[string[]]$SelectedProperty.Property += 'Caption'} {$DisplayKernel} {[string[]]$SelectedProperty.Property += 'Version'} } Get-WmiObject @WMIOS | Select-Object @SelectedProperty } Get-ComputerOS Get-ComputerOS -DisplayOSName -DisplayKernel Get-ComputerOS -DisplayAll Get-ComputerOS -DisplayOSName # Create an AD User $password = (ConvertTo-SecureString -AsPlainText 'Secret01' -Force) New-ADUser -Name 'Deborah Anderson' -SamAccountName 'deborahanderson' -AccountPassword $password -UserPrincipalName 'DeborahAnderson@jb.com' -Enabled:$true -Surname 'Anderson' -GivenName 'Deborah' -Path "OU=Management,OU=Human Resources,DC=jb,DC=com" -Description 'Manager of HR Department' -HomeDrive H: -HomeDirectory \\JBDC01.JB.COM\Home\deborahanderson -DisplayName 'Deborah Anderson' -Department 'Human Resources' # Create an AD User using splatting $ADSplat = @{ Name = 'Deborah Anderson2' SamAccountName = 'deborahanderson2' AccountPassword = $password UserPrincipalName = 'DeborahAnderson2@jb.com' Enabled = $true Surname = 'Anderson' GivenName = 'Deborah' Path = 'OU=Management,OU=Human Resources,DC=jb,DC=com' Description = 'Manager of HR Department' HomeDrive = 'H:' HomeDirectory = '\\JBDC01.JB.COM\Home\deborahanderson2' DisplayName = 'Deborah Anderson' Department = 'Human Resources' } New-ADUser @ADSplat # ForEach-Object only utilizing the process block 1..5 | ForEach-Object {$_} # ForEach-Object utilizing Begin/Process/End blocks 1..5 | ForEach-Object -Begin {$CountofObjects = 0 ; "Starting ForEach-Object loop..."} -Process {$CountofObjects++ ; "Current Object is `'$_`'"} -End {"Total amount of Objects processed: $CountofObjects"} # Build a ForEach-Object loop using Splatting $ForEachSplat = @{ Begin = {$CountofObjects = 0 "Starting ForEach-Object loop..." } Process = {$CountofObjects++ "Current Object is `'$PSItem`'" } End = {"Total amount of Objects processed: $CountofObjects"} } 'A','B','D' | ForEach-Object @ForEachSplat