Out-gridview to a single variable.

Ask your Windows 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.
Locked
User avatar
cgjackson@yahoo.com
Posts: 7
Joined: Wed Mar 01, 2017 12:54 pm

Out-gridview to a single variable.

Post by cgjackson@yahoo.com » Fri Jul 14, 2017 8:50 am

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Out-gridview to a single variable.

Post by davidc » Fri Jul 14, 2017 3:02 pm

[TOPIC MOVED TO POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Out-gridview to a single variable.

Post by jvierra » Fri Jul 14, 2017 3:33 pm

Like this:

Code: Select all

Import-Csv d:\files\divcode.csv |
out-gridview -OutputMode Single -Title 'Select a row' |
Select-Object -expand DivisionCode

Locked