Output Issue

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 7 years and 3 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

Output Issue

Post by mqh77777 »

Product, version and build: 5.2.128
32 or 64 bit version of product: 64
Operating system: Windows 7
32 or 64 bit OS: 64
PowerShell Version: 5.0

I have this code which works when run in PowerShell ISE

$PC = "AnyPC"
$wmi = [WMI] ""
$results = get-wmiobject Win32_UserProfile -ComputerName $pc | foreach-object {
$userAccount = [WMI] ("root/cimv2:Win32_SID.SID='{0}'" -f $_.SID)
$userName = "{0}\{1}" -f $userAccount.ReferencedDomainName,$userAccount.AccountName
new-object PSObject -property @{
"Name" = $userName
"LastUseTime" = $wmi.ConvertToDatetime($_.LastUseTime)
}
}
$results

But when I place this behind a button and try to display the output in my $RichTextBox display window nothing gets displayed. How come? Is it due to the psobject?
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: Output Issue

Post by mqh77777 »

I did find this code online but it does not produce nice looking output.

$GetUser1 = gci \\$pc\c$\Users | % { "$_ $($_.LastWriteTime)" } | Out-String

(it looks like this in my richtextbox window)
Administrator 09/16/2015 12:29:25
ADMINI~1 05/17/2016 08:10:51
almd 05/05/2015 14:57:03
apolina 09/17/2015 11:05:47
arthurr 09/06/2016 10:15:11

The first code I put, with PSObject displays the output in the way I want.

Name LastUseTime
---- -----------
OurCompany\medorc 10/5/2016 11:28:18 AM
OurCompany\ablesoz 10/5/2016 11:28:18 AM
OurCompany\wallac24 12/5/2016 6:24:56 AM
OurCompany\medinaj 10/11/2016 1:56:37 PM
OurCompany\stewart3 10/5/2016 11:28:17 AM
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Output Issue

Post by davidc »

[TOPIC MOVED TO THE POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output Issue

Post by jvierra »

You need to use a fixed font to make the columns line up. I recommend "Lucida Console"
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: Output Issue

Post by mqh77777 »

Hi, I am using Lucida Console for my RichTextBox output.
This topic is 7 years and 3 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