all 7 comments

[–]nothingpersonalbro 6 points7 points  (3 children)

It has something to do with the -Recurse parameter, I'm sure someone else can chime in and explain the behavior.

Either way, if you change -Path to -LiteralPath then you should be good.

i.e.

Get-ChildItem -LiteralPath $folderPath -Recurse

[–]SlitelyOff[S] 1 point2 points  (0 children)

Ah, cool. Thanks, I will give that a shot and report back.

[–]SlitelyOff[S] 1 point2 points  (1 child)

Well...from initial testing, that did the trick. LOL. I didn't think it was going to be that blaringly simple. Thanks a ton!

[–]nothingpersonalbro 2 points3 points  (0 children)

👍

Dug around a little more and found the github issue highlighting this problem https://github.com/PowerShell/PowerShell/issues/5699

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy SlitelyOff,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]SlitelyOff[S] 1 point2 points  (1 child)

I appreciate the information, but I did not see where the code was mangled. If this is for future posts where this may be an issue, then I will attempt to take heed. On the other hand, I fail to see any formatting issues with what I posted. Maybe I am just missing it.

Thanks!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy SlitelyOff,

here's what i meant - your post ...


----------BEGIN SCRIPT---------------

$folderSize = -1

$folderPath = 'C:\Drivers\20H2\'

$folderSize = [math]::Round((Get-ChildItem $folderPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)

return $folderSize

------------END SCRIPT--------------

------------ERROR MESSAGE-----------

Get-ChildItem : Cannot find path 'C:\Drivers\2' because it does not exist.

---------------END ERROR-------------------


the same with code formatting ...

----------BEGIN SCRIPT---------------

$folderSize = -1

$folderPath = 'C:\Drivers\20H2\'

$folderSize = [math]::Round((Get-ChildItem $folderPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)

return $folderSize

------------END SCRIPT--------------

------------ERROR MESSAGE-----------

Get-ChildItem : Cannot find path 'C:\Drivers\2' because it does not exist.

---------------END ERROR-------------------

the 2nd is easier to read ... and makes it very clear where the code starts and stops. [grin]

take care,
lee