powershell Formatting issues (Format-Table)

I am sure this has been answered several times over on this site:

I have a script that has about 10 columns of information. when run the script from a "Maximized" Powershell window, I get all of the output from all 10 Columns. When I run that same script from a Powershell Prompt running in "Windowed" Mode, I run into an issue where I get about 7 of the 10 columns.

Is there a way to script a function that will "Simulate" the Full Screen output inside a script running in "Windowed Mode"?

An Example of this :

$code = .\Script.ps1|ft -autosize

Open in new window



if I execute the script in a minimized window, I get a truncated output  in $code where if I run the same code in a Maximized Window I get the Full output stored to $code


I know you can do the following :

$code = .\Script.ps1|ft -AutoSize |Out-String -Width 4096

Open in new window



This will give you the full output, however I need to be able to take

$code|out-gridview 

Open in new window



and have the Table structure still intact which won't happen if I convert to string.  **Suggestions**?
LVL 14
ITguy565Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Every time that you use the "FT" this is called Format-Table, and it transforms the objects into a plain text to be displayed on the screen.

So if you want to use gridview, just don't do that.

.\Script.ps1|out-gridview 

Open in new window


Now if you need to have the $code variable filled, then do it like this:

$code= .\Script.ps1
#ToshowOnScreen:
$code | ft -autosize
#ToUseGrdView
$code | out-gridview

Open in new window

1
ITguy565Author Commented:
@Jose,

Thanks for replying,

If I run my script Maximized, I can get the output I want. That isn't the issue, I need to be able to run my script and get the full output of that powerhsell script when running from "Windowed Mode".

If you run the |ft -autosize it will display all of the columns when run "Maximized" it still only displays a few columns when run from "Windowed Mode"
0
ITguy565Author Commented:
This has been on my Radar to ask for a while, I have just circumvented the question by running my scripts maximized for a while.. Problem is I can't run some of them as a scheduled task due to this limitation.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Well, the issue is that you don't have the same width on a maximized than on a windowed. I'm assuming that you need the output so you can use it on the gridview, if you pipe the output of any "|ft"-ending command on PowerShell to a gridview you won't get what you're expected since it does the same than "Out-string" you're piping in the second example.

Now referencing the "width to get all the columns" from one "Full window" into a "Windowed mode" I don't really know if this is possible, but I don't think is possible, what you can do if you want to get all the columns always no matter if it's a windowed mode or a fullwidth, is to pipe the output into an HTML file.

$DateWithFormat = Get-Date -f yyyyMMddhhmmss  #yearMonthdayHourMinSec
$head = "<SomeCss>" #you can use this link 
$code =.\Script.ps1
$code | Convertto-Html -head $head | out-File ".\ThisFile$DateWithFormat .html"

Open in new window


For the head variable on the cmdlet convertto-html you can use this: https://blogs.technet.microsoft.com/brandev/2015/06/26/powershell-quick-html-reports-using-css-stylesheet/
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
You can run any script on the task scheduler, the problem is with your output, you can get the outputs into text files, (csv or json) or HTML files, and then process those files.

https://social.technet.microsoft.com/wiki/contents/articles/38580.configure-to-run-a-powershell-script-into-task-scheduler.aspx

My whole point is not to use the |ft when you're wanting to get all the results because it will convert the PSObject into a Plain Text to be showed on screen and well with that you lose the object that is what you need to process the data correctly (into text (plain,csv,json) or other formats like HTML..
1
Michael B. SmithExchange & Active Directory ExpertCommented:
I'm not sure that we understand what you are asking for.

But check out the FormatEnumeration control variable in PowerShell and the -Wrap parameter to FT/Format-Table.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Format-Table results are "worse" than just getting plain text - they contain formatting objects, and a lot of them, which cannot have any meaning outside of the console window. Out-GridView cannot process the Format-Table result properly. So what you do and want to do is just plain wrong.

It has been said above several times - don't mix up formatting and processing results. Formatting is for the screen; processing is for doing everything else with the results. Even storing the formatted text into a text file is questionable.

Maybe you should describe what you really want to do for us to be able to provide appropriate advice?
1
ITguy565Author Commented:
Thanks for your response guys, I will probably post my script In another question, but that is outside the scope of this particular question..


for this particular issue :


You can run any script on the task scheduler, the problem is with your output, you can get the outputs into text files, (csv or json) or HTML files, and then process those files.

https://social.technet.microsoft.com/wiki/contents/articles/38580.configure-to-run-a-powershell-script-into-task-scheduler.aspx

My whole point is not to use the |ft when you're wanting to get all the results because it will convert the PSObject into a Plain Text to be showed on screen and well with that you lose the object that is what you need to process the data correctly (into text (plain,csv,json) or other formats like HTML..


Was the closest answer to what I was looking for..

Thanks again guys.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.