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
Post a Comment