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?
Output Issue
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.
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.
Re: Output Issue
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
$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
Re: Output Issue
[TOPIC MOVED TO THE POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.