# Need Help Select-Object Argument

**URL:** <https://forums.powershell.org/t/need-help-select-object-argument/14709>\
**Category:** PowerShell Help\
**Created:** [July 27, 2020, 8:24am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709 "2020-07-27T08:24:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncrooks](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@ncrooks](https://forums.powershell.org/u/ncrooks)\
**Post date:** [July 27, 2020, 8:24am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/1 "2020-07-27T08:24:27Z")

</div>

How do I build the select statement argument so I can call select dynamically?

When I reference my variable in the select statement it concatenates into a single string - (expansion?)  
If I call the variable spearately then copy and paste the output of the variable I get what I need.

```auto

$import = import-csv 'C:\Users\NickCrooks\OneDrive - xyzworkplace\roleproject\20200723_MasterPermissionsList.csv' #$env:userprofile\downloads\rolepermissiondifferences149.csv #MasterRoleComparison
$users = Import-Csv 'C:\Users\NickCrooks\OneDrive - xyzworkplace\roleproject\SearchExports\20200723_userimport.csv' #$env:userprofile\Downloads\NJCEmployeeSearchResults329.csv #roleNotNull_users
$titlehash = $users | ?{$_.role -notin ('System Admin - view only','Integrations')} | select role, name | Group-Object -Property name -AsHashTable
#$ref = $import | select Category, Permission

#region operation
foreach($key in $titlehash.keys) {
$val = $titlehash[$key]
$sb = [System.Text.StringBuilder]::new()
#https://powershellexplained.com/2017-11-20-Powershell-StringBuilder/

if($val.name.GetType() -match 'System.object') {
#$Title = New-Object psobject
#$Title | Add-Member -MemberType NoteProperty -Name "$($val.name[0])" -Value $ref #moved this
#Write-host $val.name[0] -ForegroundColor yellow
#$val."role" | select -Unique
write-output $roles.count -Verbose

#write-verbose "$roles found" -Verbose

$val | %{
[string]$role = $_.role
#$role
$sb.Append('"'+"$role"+'",')
}
$list = $sb.ToString() #Need to trim the last comma off, so I need substring method
$list.Substring(0,($sb.Length)-1)
$import | select -Property $($list.Substring(0,($sb.Length)-1)) | Out-GridView
#Here's the output of $list.Substring(0,($sb.Length)-1) - and it works if I copy & paste the text below
#"Candidate Relations","Practice Director","Candidate Relations - TAF","Human Resources Assistant","Outlook -App","Permission"
pause
}
else {
#Single values whose type is different
write-host $val.name.ToString() -ForegroundColor Red
$val."role"
$import | select permission, $val.role | Export-csv "C:\Users\NickCrooks\Desktop\role\$($val.name).csv" -force
#pause
}
}

```

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [July 27, 2020, 8:34am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/2 "2020-07-27T08:34:10Z")

</div>

```
$($list.Substring(0,($sb.Length)-1))
```

Above expressions gives a string here which has commas and treated whole as a property name to select. So here you just need to split it by comma which will give you an array and each item in the array will be treated as property to select as -Property will accept array of strings.

```
($list.Substring(0,($sb.Length)-1) -split ',')
```

---

<div class="post-metadata">

**Author:** ![ncrooks](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@ncrooks](https://forums.powershell.org/u/ncrooks)\
**Post date:** [July 27, 2020, 8:50am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/3 "2020-07-27T08:50:20Z")

</div>

So close!

Thanks for the response kvprasoon!

Unfortunately I get empty properties/columns using this method - columns are correct but no data whereas if I type it manually I get data back

---

<div class="post-metadata">

**Author:** ![ncrooks](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@ncrooks](https://forums.powershell.org/u/ncrooks)\
**Post date:** [July 27, 2020, 9:16am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/4 "2020-07-27T09:16:37Z")

</div>

Here’s what I see

```auto
$import | select -Property ($list.Substring(0,($sb.Length)-1) -split ',')

"Candidate Relations" :
"Practice Director" :
"Candidate Relations - TAF" :
"Human Resources Assistant" :
"Outlook - NetSuite" :

"Candidate Relations" :
"Practice Director" :
"Candidate Relations - TAF" :
"Human Resources Assistant" :
"Outlook - NetSuite" :

```

Here’s what I was hoping for:

```auto

$list.Substring(0,($sb.Length)-1)
"Candidate Relations","Practice Director","Candidate Relations - TAF","Human Resources Assistant","Outlook - NetSuite"

PS C:\> $import | select "Candidate Relations","Practice Director","Candidate Relations - TAF","Human Resources Assistant","Outlook - NetSuite"

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : None
Practice Director : None
Candidate Relations - TAF : None
Human Resources Assistant : None
Outlook - NetSuite : None

Candidate Relations : Full
Practice Director : Full
Candidate Relations - TAF : Full
Human Resources Assistant : None
Outlook - NetSuite : None

```

---

<div class="post-metadata">

**Author:** ![ncrooks](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@ncrooks](https://forums.powershell.org/u/ncrooks)\
**Post date:** [July 27, 2020, 9:19am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/5 "2020-07-27T09:19:44Z")

</div>

`$import | select -Property ($list.Substring(0,($sb.Length)-1) -split ',').replace('"','')`

This is it!!

Why does that work, when if typing it out I would need to add the quotes?

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [July 27, 2020, 9:38am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/6 "2020-07-27T09:38:25Z")

</div>

Why are you collecting the role names like this?

---

<div class="post-metadata">

**Author:** ![ncrooks](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@ncrooks](https://forums.powershell.org/u/ncrooks)\
**Post date:** [July 27, 2020, 9:43am UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/7 "2020-07-27T09:43:05Z")

</div>

Most natural way for me to do so/Lack of experience doing it other ways 😃

Huge thanks to everyone here for all the knowledge/help.

As far as Netsuite (system it comes from) the output is a csv, where properties are (first two are always the same)  
Category,Permission,Role1,Role2,Role3, etc.

Separately I have a csv of users where their role(s) are included.

What did you have in mind, Doug?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/need-help-select-object-argument/14709/8 "2024-05-16T20:29:11Z")

</div>


