format and display in htm

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

format and display in htm

Post by mqh77777 »

I am using PowerShell Studio 5.3.131.

I have this code that works fine inside of PowerShell ISE

get-WmiObject -class Win32_Share -ComputerName "machine1" | Select-Object Caption, path, name | ConvertTo-HTML | Out-File c:\Temp\shares.htm
Invoke-Expression C:\temp\shares.htm

it displays with 3 columns within Chrome.


Caption path name
Remote Admin C:\WINDOWS ADMIN$
Default share C:\ C$
Remote IPC IPC$



But when I put the same code within PowerShell Studio it displays way way more data. It displays all of this
PSComputerName Status Type Name __GENUS __CLASS __SUPERCLASS __DYNASTY __RELPATH __PROPERTY_COUNT __DERIVATION __SERVER __NAMESPACE

Why and how do I make it only display the 3 columns I need?

Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format and display in htm

Post by jvierra »

It works fine for me in PSS.
Try using this in a new PSQ file.
  1. get-WmiObject -class Win32_Share |
  2.     Select-Object Caption, path, name |
  3.     ConvertTo-HTML |
  4.     Out-File c:\Temp\shares.htm
  5. Invoke-Expression C:\temp\shares.htm
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: format and display in htm

Post by mqh77777 »

OK, yours worked. But why? Do we not have basically the same code?

thank you.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format and display in htm

Post by jvierra »

Go back and look at the actual code that is failing. Somewhere there is a mistake. I suspect the whole script may have some simple issue that is not obvious but now that you have a base proof you should be able to find the mistake. Sometimes pasting to copies of the same code and only editing the first copy will fool us into thinking we are running the fixed code. Step through the code with the debugger to verify that it is actually executing the code you think it is executing.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: format and display in htm

Post by mqh77777 »

ok, this code works as expected.

if (Test-Path c:\Temp\shares.htm) {Remove-Item c:\Temp\shares.htm}
get-WmiObject -class Win32_Share -computername $pc |
Select-Object Caption, path, name |
ConvertTo-HTML |
Out-File c:\Temp\shares.htm
Invoke-Expression C:\temp\shares.htm

I have another question and I'm not sure if it is possible within PowerShell Studio. How would I change the colors in IE (or Chrome) when this code runs? When this code runs it has black font on a white background. I'd like to see black on a soft yellow. Or yellow on black. I've seen PowerShell scripts that format HTML output but is that possible within PowerShell Studio?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format and display in htm

Post by jvierra »

You need to add a style sheet to the conversion.

help convertto-html -full
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: format and display in htm

Post by mqh77777 »

help convertto-html -full does not say anything about color and from what I've Googled ConvertTo-HTML does not change the color. That seems to require more coding.

Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: format and display in htm

Post by jvierra »

HTML uses style sheets to set the colors.

See: https://www.w3schools.com/css/default.asp
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked