Link to home
Start Free TrialLog in
Avatar of ITguy565
ITguy565Flag for United States of America

asked on

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**?
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

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

Avatar of ITguy565

ASKER

@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"
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.
ASKER CERTIFIED SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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?
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.