How can I enforce powershell to use
Format-Table -auto
as a default formatting when writing a returned array of objects to the console? Thanks
How can I enforce powershell to use
Format-Table -auto
as a default formatting when writing a returned array of objects to the console? Thanks
If you OK calling the cmdlet every time and if you have at least PowerShell v3.0 then you can set a
$PSDefaultParameterValues
which you can read more about at about_Parameters_Default_Values.The syntax that would satisfy your need would be:
So we add in the switch by setting it to
$true
.To remove this you would have to do it much the same as you would a hashtable element
From the aforementioned article here is some pertinent information as to how to deal with these.
Outside of that I am not sure as it would be difficult to change in a dynamic sense. You would want to be sure that data sent to the stream appears on screen in the same way that
format-table -auto
does but you would have to make sure that it does not affect data so that you could not capture it or send it down the pipe.You are looking at creating custom output format files, like Frode F. talks about, then you would need to consider looking at about_Format.ps1xml but you would need to configure this for every object that you would want to display this way.
FileSystem.format.ps1xml, for example, would govern the output from
Get-ChildItem
.Format-Table
is more dynamic and I don't think you can say just useFormat-Table
in that file.