Let's say I have a folder with name "Folder [MyGitHub]" and it has one subfolder with name "1"
When I try the following powershell,
$sourcePath = "D:\Folder [MyGitHub]"
[array]$buildDirectories = Get-ChildItem $sourcePath | Sort-Object Name
Write-Output $BuildDirectories[0]
The exception is:
Cannot index into a null array. At line:1 char:1 + Write-Output $BuildDirectories[0] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
I have tried escaping with backtick (`), backslash, single and double quotes, but the issue was not resolved. The code is working if [] are not present in the folder name string - example Folder (MyGitHub).