question

JoeH-0944 avatar image
0 Votes"
JoeH-0944 asked JoeH-0944 answered

PowerShell and string search

I need to pull the account of the user that has a Microsoft Store application installed from the string below. In this example it would be Pete. It should only return what's in the first set of [] brackets and no others. What's the best method in PowerShell to do this?

{S-1-5-21-2622660536-623557165-1234864593-1001 [Pete]: Installed, S-1-5-18 [S-1-5-18]: Staged}

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

This works:

 $s = "{S-1-5-21-2622660536-623557165-1234864593-1001 [Pete]: Installed, S-1-5-18 [S-1-5-18]: Staged}"
    
 if ($s -match "\[(.+?)\]:"){
     "Found it!"
     $saved = $matches[1]
 }
 else{
     "No 'Pete' here. :-("
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoeH-0944 avatar image
0 Votes"
JoeH-0944 answered

LOL

Thanks for the help.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.