Sorry about that, it was not clear to me that the PRE button was the code button even through it’s clearly stated
The above would work but is there no way to construct the statement using +=?
I have a gui with checkboxes for each property and I want to only show the properties for the checked properties.
I thought the If statements would be what I needed. Using the += would just give me the properties I needed.
You will have to pass the properties you want as an array. Arrays have a fixed size when you create them. You could use following trick to ‘create’ a new array with the content of the old one added by something you want:
# @() is an array.
# Force Selectarg to be a 1 element array
$SelectARG = @() + 'Name'
# add samaccountname as a element to the array
$SelectARG += 'Samaccountname'
# now that $Selectarg is an [string[]]
# you can pass it to -property which accepts arrays
get-aduser tuser | Select -property $SelectARG
Your attempt wasn’t working because you were creating a string containing commas.
# this creates a string
$SelectARG = 'Name'
# this appends a comma space into the string
$SelectARG += ', Samaccountname'
#what you wrote was getting interpreted as
Select -property 'Name, Samaccountname'