resolver101
resolver101

Reputation: 2255

Powershell: string manipulations

I'll explain what i want by example, not sure how to explain it another way.

Heres the code im using :

Get-WmiObject win32_share | select name, path

an example entry is from the above is:

name path
ADMIN$ C:\windows
C$ C:\

I want to put all names and paths into one variable. I want the string to look something like:

"Name: admin, path: C:\windows ; Name: c$, path: C:\ ; ect ect.."

Any ideas?

Upvotes: 0

Views: 546

Answers (2)

manojlds
manojlds

Reputation: 301157

Slight modification in approach from @SINTER's answer and using more POSH syntax:

$out="";Get-WmiObject win32_share | %{ $out+="Name: {0}, Path: {1}; " -f $_.Name, $_.Path}

Upvotes: 3

Klark
Klark

Reputation: 8280

Something like this:

[string]::Join("; ", (Get-WmiObject win32_share | % { [string]::Format("Name: {0}, Path: {1}", $_.Name, $_.Path)}))

Upvotes: 0

Related Questions