JoeP wrote: ↑31 Jan 2022, 19:59
...You can spend immense amounts of time at that site.
But that would be bad,. … wouldn’t it? – I wouldn’t have as much time to be here! ……. :)
But seriously I will take a look. It can’t be any worse than taking script from GitHub, hopefully the stuff there has a better success rate in the coding actually working and doing half way what it’s intended to do. There may be some relation to stuff there and some “module” thing I “invoked” a while back to usefully turn a PowerShell script into an executable
.exe thing
The general article and Blog site information on the internet that I am finding continually seems to be very bad – I don’t doubt some of the people writing the stuff know what they are talking about but almost all seem to be obfuscating it behind what they write
On YouTube, as most usual, you need a lot of time to wade through the 95% of rubbish to find the 5% that is good or OK. This guy is OK in places, but you need to be fluent in broken Swahili-Hindi-English to understand him.
https://www.youtube.com/watch?v=FVs42IU ... j-N&t=720s
_._______________________________________________________________________________________-
I have got a bit further , by about 80% experiment, 20% internet research. Of the 20%, most of it was trying to understand the very fundamental theory of Piping and similar things then starting from scratch again myself
I have figured out what/ where the strange truncating problem is coming from.
So now I can get consistently the three column table, and am close to understanding all about how to do it. I probably need just a bit longer to get a 100% understanding of the syntax.- I am almost there.
_1 Coming back to the very simplified, shortened code lies of this sort of form: Truncation Oddity
Get-Service > test.txt # Output to text file
Get-Service|Format-Table name,displayname,starttype > test.txt # Output to text file
Get-Service|Format-Table name,displayname,starttype 1> test.txt # Output to text file
Get-Service|Format-Table name,displayname,starttype # output in blue console window
I can consistently get now a simple three column table from those sort of lines. …
How? :-
My experiments, and what I picked up from research are telling me that the width you end up with for the final output is related to the width of the window PowerShell window from which you run the code line.
That goes for the width you end up with, ( in other words if/what gets truncated), both in
_ the direct
blue window console output
And
_ the
success stream redirected stuff,
> , that finds its way in the final text file.
In simple terms, the answer is this: make the PowerShell window very wide, and your text file ( or console output ) will have all the columns.
I am not sure yet of the exact correlation between the width of the console and width of “truncation” in the console and the final text file: Sometime it seems to tie up very well ;Other times it may be you see all columns in one but not in the other. But if the PowerShell window is very wide, then it’s a sure bet you will see all 3 columns in both.
But that is obviously a bit of a fiddle and maybe not always a practical solution
_2 Doing it properly, practical Solution
The final sensible solution lies in using the full syntax.
( the variations of the
> are
something of a shorthand, - not really a shorthand or
Alias, - I expect possibly they are some combination of a shorthand and an attempt at backward compatibility to the black command,
cmd, window stuff )
I am not 100% there yet, mostly because I am not fully sure I understand the syntax yet, but this is close to the sort of syntaxes that will get consistently a 3 column table like output in a text file, regardless of your PowerShell window width.
Code: Select all
Get-Service|Format-Table -AutoSize name,displayname,starttype| Out-File -FilePath test.txt -Width 1000
Get-Service|Format-Table -AutoSize name,displayname,starttype| Out-File -FilePath 'C:\Users\Elston\Desktop\test.txt' -Width 1000
It looks very beautiful in the PowerShell ISE window
Get-Service|Format-Table -AutoSize name,displayname,starttype| Out-File -FilePath test.txt -Width 1000
I have not seen the
-AutoSize make any difference yet. But some people suggested you needed it, so until I know better I am including it.
I set the figure
1000 arbitrarily after I found
_ that a minimum figure of between about 120 and 160 was needed to get me all the columns in my current example
, and
_ I saw no ill effects from using an extremely large number.
So as I don’t 100% fully understand what’s going on yet, I guessed a fairly big number would be OK.
Notes:
_(i) It is very important to liberally use the
Clear command and keep your eye on if a scroll bar appears on the
blue console when doing any experiments: This is because the “
effective” PowerShell console width increases when you have a scroll bar. The scroll bar is somehow automatic, I think. The scroll bar can, for example be somehow “invoked” be a previous long ( wide ) code line.
The point I am making here is that if a scroll bar is present that lets you scroll a long way to the right, then likely the simplified code line of like
Get-Service|Format-Table name,displayname,starttype > test.txt will very likely get all your columns in the text file even if the window you have in front of you is very narrow.
_(ii) When checking out your text file during any experiments, make sure you always scroll across to the right, as the last column may initially be hidden across to the right when you open up the text file. ( In other words the text file may open with a scroll bar, and to see the last column you may need to scroll to the right )
Alan
Sure you can give me a DVM instead, when you take the AVOmeter out of my cold dead hands,