# advanced function process block problems

**URL:** <https://forums.powershell.org/t/advanced-function-process-block-problems/6517>\
**Category:** PowerShell Help\
**Created:** [May 25, 2016, 9:47pm UTC](https://forums.powershell.org/t/advanced-function-process-block-problems/6517 "2016-05-25T21:47:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter-marsh](https://avatars.discourse-cdn.com/v4/letter/p/58f4c7/32.png) [@peter-marsh](https://forums.powershell.org/u/peter-marsh)\
**Post date:** [May 25, 2016, 9:47pm UTC](https://forums.powershell.org/t/advanced-function-process-block-problems/6517/1 "2016-05-25T21:47:20Z")

</div>

I am trying to write an advanced function that will grab all files from an archive directory, list them, and total their size so I can see when I’m about to fill up a DVD. Below is a primary piece of script. When I insert this in the process script block by itself, does this mean every object produced by the get-childitem cmdlet is put thru a pipeline? Or just one big object? Is there even a pipeline involved at this point?  
If I try to pipe this command to a select-object cmdlet, I can see the specified properties I’ve selected. However, if I then try to pipe to a hash table I get an error message stating:  
At line:5 char:12

- 

```
       $hash=[ordered]@{

```

- 

```
       ~~~~~

```

Expressions are only allowed as the first element of a pipeline.  
+ CategoryInfo : ParserError: (🙂 , ParentContainsErrorRecordException  
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

```
Get-ChildItem -Path C:\Users\Peter\Documents\Test_Archive -Filter '*.*' -Recurse -file -attributes archive
```
Any advice? Really getting frustrated.
Peter
```
```

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [May 26, 2016, 10:01am UTC](https://forums.powershell.org/t/advanced-function-process-block-problems/6517/2 "2016-05-26T10:01:21Z")

</div>

This will display the size (in MegaBytes) of your archive and number of files. If you use the ‘-Export’ switch, it will export a list of files to each directory. You can use Robocopy as an alternative to Get-ChildItem for better performance.

```
function Get-ArchiveSize {
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline)]
        [string[]]$Path,
        [switch]$Export
    )

Process {
    foreach ($string in $path){
    Write-Verbose "Searching [$string]"
    $files = Get-ChildItem -Path $string -File -Attributes Archive -Recurse
    $measure = $files | Measure-Object -Sum Length | 
    Select-Object @{n='Sum';exp={"{0:N2} (MB)" -f ($_.Sum / 1MB)}},
    Count | Format-Table -AutoSize
    $measure
    If ($Export){$files.FullName | Out-File "$string\filelist.txt" -Append}
    }
} 
}

# Examples:
# Get-ArchiveSize -Path "\\path\one","\\path\two" -Verbose
# "\\path\one","\\path\two" | Get-ArchiveSize -Verbose -Export
```

---

<div class="post-metadata">

**Author:** ![anthony-stringer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/anthony-stringer/32/593_2.png) [@anthony-stringer](https://forums.powershell.org/u/anthony-stringer)\
**Post date:** [May 26, 2016, 4:47pm UTC](https://forums.powershell.org/t/advanced-function-process-block-problems/6517/3 "2016-05-26T16:47:35Z")

</div>

> You can use Robocopy as an alternative to Get-ChildItem for better performance.

now that i know how to use it, i do enjoy utilizing robocopy when necessary, however, i have not seen many detailed comparisons of performance vs get-childitem. could you please share how you determined this? i would like to use whichever is fastest, of course.

---

<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:41pm UTC](https://forums.powershell.org/t/advanced-function-process-block-problems/6517/4 "2024-05-16T20:41:10Z")

</div>

Closed on May 16, 2024, 8:41pm UTC


