Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Calling a Function Within a For-Each in Powershell

$
0
0

Error:

Unexpected token 'in' in expression or statement.
At :line:1 char:22
+ ForEach-Object ($i in  <<<< $fs_size_info) { $i.Name.Name, GetGB($i.Sum)  }


Code:

foreach ($i in $fs_size_info) { $i.Name.Name GetGB($i.Sum) }

If I omit the function from inside this foreach, it works perfectly, and I can access $i.Sum within the foreach as well. The problem arises when I try to call a function from inside the foreach. GetGB simply returns a more readable format e.g. GetGB(1024) will return "1 K" etc...

I don't understand what I'm doing wrong, unless you cannot call a function inside a foreach statement.... am I missing something?

Thanks


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>