Forwarding Parameters

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

To forward function parameters to a cmdlet, use $psboundparameters automatic variable and splatting. Here is a sample:

function Get-BIOS($ComputerName, $Credential) {
  Get-WmiObject Win32_BIOS @psboundparameters
}

Your function Get-BIOS works both locally and remotely. Only the parameters submitted by the user will actually be forwarded to Get-WmiObject.

Twitter This Tip! ReTweet this Tip!


Posted Sep 16 2011, 06:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.