November 2nd, 2012

PowerTip: Automatically Format Your PowerShell Table

Doctor Scripto
Scripter

Summary: Set a default preference variable and avoid typing –autosize and –wrap with Windows PowerShell 3.0.

Hey, Scripting Guy! Question How can I avoid always having to type –autosize and –wrap with the Format-Table cmdlet? I am using Windows PowerShell 3.0.

                      Hey, Scripting Guy! Answer Set the $PSDefaultParameterValues automatic variable with the appropriate default values. This can be done on a Windows PowerShell session basis or stored in your Windows PowerShell profile. Here is an example of setting the default behavior of the Format-Table cmdlet to always autosize and wrap the output.

                                 $PSDefaultParameterValues=@{“Format-Table:autosize”=$true;”Format-Table:wrap”=$true}

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.