2

I'm getting a list of SID numbers using $list = gwmi win32_userprofile | ft localpath, sid -a and I want to split each line of the output ($list) into a separate variable. I can't figure out how to do this - any suggestions on the most efficient way? An array? If so, how?

The purpose of this is to then further filter the output to display only SID's that start with S-1-5-21-*, and then assign numbers to each resulting line, allowing the user to select a user SID for domain migration by typing a number.

2
  • can you be more clear please, you want to store each line of the output in an variable or just the line which start S-1-5-21-* ? Commented Nov 17, 2015 at 20:06
  • Ultimately yes, each line (there will be multiple lines) that starts with S-1-5-21-* should be stored as a separate variable. Commented Nov 17, 2015 at 20:40

1 Answer 1

2

Why do you need to format table? This is meant for console output..

Also, a better way to filter would be using the Where-Object cmdlet

$list = gwmi wi32_userprofile | Where { $_.sid -like "S-1-5-21-*"} | Select localpath, sid

Then you can use $list like an array.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that works great! I was formatting it so I could see the results easily. Your answer works perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.