I have a portion of a powershell script that checks locations and verifies the count of files, then runs checks based on the count. The powershell script is ran on multiple machines, one of which is running powershell 2.0.
I'm using something like:
$folder = Get-Item "Parent Folder"
$files = (Get-ChildItem $folder.Fullname)
When I check $files.Count it will be accurate in versions of powershell greater than 2.0.
In Powershell 2.0, files.Count will not return anything if $files only contains 1 file. If there is more than 1 file, then it returns the correct number count (non-null).
I'm assuming this has to do with $files not being an array if Get-ChildItem only returns one value.
I know that checking the powershell version and modifying the script per version would resolve this issue, but I'd prefer to avoid it.
Is there some other way to check the count uniformly across multiple versions of powershell?