powershell - Access content os variable line by line in power shell -


i storing output of command in variable. want access content of line line.

$outputvariable = (dir | % { $_.fullname -replace "c:\\","" }) | out-string; $outputvariable 

output follows:-

d:\asgn5 d:\assignment 5 

so want access output of variable line line first want have d:\asgn5

we can have data $$outputvariable[0..n]

but want know there other way access line line?

from the doc

by default, out-string accumulates strings , returns them single string, can use stream parameter direct out-string return 1 string @ time.

but don't have use out-string @ all. let use foreach loop on object return get-childitem (dir) command :

$outputvariable = (dir | % { $_.fullname -replace "c:\\","" }) $outputvariable |foreach {"value $_"} 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -