PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

Latest Scripts

03-30-2015 - Add windows system variable
03-30-2015 - Archive files with x days old
03-21-2015 - Run CMD\BAT as PS1

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Using Splatting

With splatting, you can call cmdlets and programmatically control the parameters you submit.

To do this, add the parameters and values to a hash table, then submit the hash table to the cmdlet. This works with any cmdlet.

Here is an example:

# classic:
Get-ChildItem -Path c:\windows -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue


# Splatting
$params = @{}
$params.Path = 'c:\windows'
$params.Filter = '*.ps1'
$params.Recurse = $true
$params.ErrorAction = 'SilentlyContinue'
Get-ChildItem @params

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.