Powershell ArrayList turns a single array item back into a string
You need to force the output into an array.
@((Get-ChildItem C:\Directory -dir).Name)
If you want to use an ArrayList, the constructor is just expecting an Array or another ArrayList. You can build off what @DanielMann said and do something like this:
New-Item -Path C:\TestDirectory\SubDirectory -Force | Out-Null # Creates one folder in C:\TestDirectory[System.Collections.ArrayList] $ArrayList = @((Get-ChildItem C:\TestDirectory -Directory).Name)Write-Host "Total directories: $($ArrayList.Count)"Remove-Item -Path C:\TestDirectory -Recurse
As you can see, I am just wrapping the output of (Get-ChildItem).Name
in an array @()
.