A cmdlet which returns multiple objects, what collection type is it, if any? [PowerShell]

Cmdlets themselves typically use no collection type in their output.[1]: They emit individual objects to the pipeline, which can situationally mean: zero, one, or multiple ones. This is precisely what Get-ADUser does: the specific number of output objects depends on the arguments that were given; that is why the Get-AdUser help topic only mentions scalar … Read more

Objects with no ‘.Count’ Property – use of @() (array subexpression operator) vs. [Array] cast

In PSv3+, with its unified handling of scalars and collections, any object – even $null – should have a .Count property (and, with the exception of $null, should support indexing with [0]). Any occurrence of an object not supporting the above should be considered a bug; for instance: Using this intrinsic (engine-supplied) .Count property unexpectedly … Read more

For PowerShell cmdlets, can I always pass a script block to a string parameter?

# Delay-bind script-block argument: # The code inside { … } is executed for each input object ($_) and # the output is passed to the -NewName parameter. … | Rename-Item -NewName { $_.Name -replace ‘\.txt$’,’.log’ } The call above shows an application of a delay-bind script-block ({ … }) argument, which is an implicit … Read more