Out-gridview to a single variable.

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 6 years and 9 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
cgjackson@yahoo.com
Posts: 7
Last visit: Tue Aug 07, 2018 5:16 am

Out-gridview to a single variable.

Post by cgjackson@yahoo.com »

I trying to get out this code to a variable. I get the pop-up screen, but don't see how to get it to a variable.
Import-Csv "d:\files\divcode.csv" |
select-object -property * |
out-gridview -OutputMode Single -Title 'Select a row' |
ForEach-Object {
$DevCode = $_DivisionCode
}

Write-host "$DevCode"


The input is:
"DivisionCode","Division Name"
"MY","MY - Northeast Concord"
"SO","SO - Southern"
"PA","PA - Pennsylvania"

I would like to select like MY row and get the output to be just the first colurm.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Out-gridview to a single variable.

Post by davidc »

[TOPIC MOVED TO POWERSHELL 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: Out-gridview to a single variable.

Post by jvierra »

Like this:
  1. Import-Csv d:\files\divcode.csv |
  2.          out-gridview -OutputMode Single -Title 'Select a row' |
  3.          Select-Object -expand DivisionCode
This topic is 6 years and 9 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