powershellprofileuser-accountsout-gridview

Powershell: Out-GridView with List of User Profiles (Get-ChildItem -path \\$env:COMPUTERNAME\c$\users\)


Basic usage question:

When I run

Get-ChildItem -path \\$env:COMPUTERNAME\c$\users\ | Out-GridView -Title "Select from User Accounts" -PassThru

all looks good, I get a nice pop-up dialog with user accounts to pick from, one account per row. Fields are Mode, LastWriteTime, Length, and Name (perfect, I'll pick out Name and LastWriteTime later, OK there.)


However, when I make it a variable in between, lisk this...

$useraccountsall = Get-ChildItem -path \\$env:COMPUTERNAME\c$\users\
$useraccounts = Out-GridView -InputObject $useraccountsall -PassThru -Title "Select from User Accounts"

I get one row with many unfamiliar columns, like: Length, LongLength, Rank, SyncRoot, IsReadOnly, IsFixedSize, IsSynchronized, Count SyncRoot seems to contain the list of usernames, and maybe more info.

Q: How do I change the second code to show GridView output like the first?


Solution

  • Thank you Santiago Squarzon! Got it, skip -InputObject, just pipe it in.

    $useraccounts = $useraccountsall | Out-GridView -PassThru -Title "Select from User Accounts"