34 lines
801 B
PowerShell
34 lines
801 B
PowerShell
|
function Test-IsArrayValid {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Tests if an array is valid.
|
||
|
Valid means has contents, is an array.
|
||
|
No contents, or only null contents, does not constitute a valid array.
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
Param(
|
||
|
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
|
||
|
[object]$array
|
||
|
)
|
||
|
|
||
|
$isValid = $false
|
||
|
|
||
|
if ($null -eq $array) {
|
||
|
return $isValid
|
||
|
}
|
||
|
|
||
|
if ($array -is [System.Collections.IEnumerable] -and $array -isnot [string]) {
|
||
|
if ($array.Count -gt 0) {
|
||
|
for ($i = 0; $i -lt $array.Count; $i++) {
|
||
|
if ($null -ne $array[$i]) {
|
||
|
$isValid = $true
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return $isValid
|
||
|
}
|
||
|
|
||
|
Set-Alias -Name Any -Value Test-IsArrayValid
|