How to check PowerShell function parameters allowing empty arrays?

I have a problem similar to THIS ONE

I go over to the function of 3 arrays and I check the type of the object this way

function _TEST { [CmdletBinding()] param ( [parameter(mandatory=$true)] [array]$Path, [parameter(mandatory=$true)] [array]$RW, [parameter(mandatory=$true)] [array]$RO ) process { # my code } 

This works if I do not pass an array of functions without elements, in which case it returns this _TEST : Cannot bind argument to parameter 'Path' because it is an empty collection. error _TEST : Cannot bind argument to parameter 'Path' because it is an empty collection.

Is there a way to solve a problem like [AllowEmptyString()] in a related question, or do I need to write my own code to check the input variable?

+4
source share
1 answer

Try the following:

 param ( [parameter(mandatory=$true)] [AllowEmptyCollection()] [array]$Path ) 

Link

Parameter Check Attributes

+14
source

Source: https://habr.com/ru/post/1487257/


All Articles