Help with text parsing

An edge device returns a text blob at me from the following code run on a remote server (this code works)

$all_accounts = Invoke-Command -ComputerName $server -ScriptBlock {Invoke-WebRequest -Uri $args[0] -UseBasicParsing -Credential $args[1]} -ArgumentList $get_all_accounts_url, $credential -ErrorAction Stop

$all_accounts is a variable with this info (below)

 

what would be the best way to parse out the accounts after “admin=”

root="value"
bin="value,value,value"
daemon="value,value,value"
sys="value,value"
tty="value,value,value"
admin="value,value,value,value"

Its so easy in PowerShell way, would like you to put your hands in. Please read below help documentation.

Get-Help Select-String -Full
Or
Get-Help Select-String -Online
Get-Help ConvertFrom-String -Online

Once you start, feel free to post your issues here, we are here to help you.

Hmm. You can use -like or a regex -match to get the right string, and then a -replace for the quotation marks and a -split to get each value individually.

It’d probably look something like this, I suppose?

$AdminAccounts = $All_Accounts.Where{ $_ -like 'admin*' } -replace 'admin=|"' -split ','

Hi sorry I should’ve said, this is my first attempt at select-string and tried it before posting

$admin_accounts = $all_accounts | Select-string -Pattern "admin=" -Context

doesn’t do what I think it should, it just returns the entire text blob

Got it, here is a similar topic. The reason for it is also mentioned in this post.

https://powershell.org/forums/topic/select-string-for-linux-users/

ahh figured it out.

i needed to do this prior to select string

$all_accounts -split "`n"

 

sometimes talking to yourself out loud on the internet works

:slight_smile: