0

I am trying to convert a PowerShell cmdlet's output from a table view, into something more like an array. I used a list format to cut as much junk data as possible. Currently, I use the following code to get this output:

Get-AccountsWithUserRight -Right SeNetworkLogonRight | Format-List -Property SID |Set-Variable -Name "Accounts"
$Accounts

Output:

SID : S-1-5-32-583

SID : S-1-5-32-551

SID : S-1-5-32-545

SID : S-1-5-32-544

I am unsure of how to use formatting/other properties to cut out the 'SID' string, and just return an output such as "S-1-5-32-583,S-1-5-32-551,etc". I need to do this as I wish to use the output in another cmdlet, and the extra data is causing errors.

Xioner
  • 3
  • 1

1 Answers1

1

Only ever use Format-* cmdlets for display formatting; never use them if data must be programmatically processed. Format-* cmdlets output formatting instructions, not data - see this answer.

Also, to save output in a variable, it's simpler to assign to it rather than to use Set-Variable:

# Save the account objects in a variable.
$Accounts = Get-AccountsWithUserRight -Right SeNetworkLogonRight

If you then want to output / use just the SID values:

$Accounts.SID
mklement0
  • 312,089
  • 56
  • 508
  • 622