Add expression to table and do a foreach on that expression

Ask your PowerShell-related questions, including questions on cmdlet development!
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 5 years and 5 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
jaytolkte
Posts: 1
Last visit: Mon Oct 15, 2018 8:15 am

Add expression to table and do a foreach on that expression

Post by jaytolkte »

Hi all,

I have a varible with the following fields:

onlineuser,FirstName,LastName,LoggedonHost,sinceloginHRS, UserGroup,

Now i'm adding a new field called 'captured username'. on this field i want to run get-tssesion and capture the active user into this field. This command below isnt working, how do i add a for each on that paticular field?

$sqlcmddata | select-object onlineuser,FirstName,LastName,LoggedonHost,sinceloginHRS, UserGroup,@{Name="CapturedUserName"; Expression={
Get-TSSession -ComputerName $_.loggedonhost -State Active | select username} }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Add expression to table and do a foreach on that expression

Post by jvierra »

The command will return a collection of objects and not just a single name.
This topic is 5 years and 5 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