# Don't understand why it won't work

**URL:** <https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177>\
**Category:** PowerShell Help\
**Created:** [September 21, 2019, 5:09pm UTC](https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177 "2019-09-21T17:09:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![powersam](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@powersam](https://forums.powershell.org/u/powersam)\
**Post date:** [September 21, 2019, 5:09pm UTC](https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177/1 "2019-09-21T17:09:13Z")

</div>

Simple but don’t understand

If I type

$tot =0

gci |%{$tot += $\_.length}

It will return value

$tot = gci |%{$tot += %\_.length}

It return nothing.

why ?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 21, 2019, 5:55pm UTC](https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177/2 "2019-09-21T17:55:04Z")

</div>

Hmmm … for me

```
$tot = 0
Get-ChildItem |
ForEach-Object{
$tot += $_.length
}
```
  
… does not return anything … if you meant it fills the variable $tot with the cumulated sizes of the files of the current directory - yes it does that.

But what should “ **%\_** ” be? What do you expect it to do? Don’t you get an error (a lot of errors?)

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 22, 2019, 10:39pm UTC](https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177/3 "2019-09-22T22:39:32Z")

</div>

> [@](#):
>
> $tot = gci |%{$tot += %\_.length}

REgardless of the syntax , it won’t return anything. The scriptblock should spit something for the $tot variable to catch. In this case its always caught in $tot inside the foreach statement.

As @Olaf-Soyk mentioned, didn’t you get any errors with that syntax ?

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/dont-understand-why-it-wont-work/13177/4 "2024-05-16T20:32:05Z")

</div>


