I am trying to list out all directories and their sub directories on the network share. Issue I am facing is the roots1.txt file has just network folders for example \\xxxx and not \\xxxx\xx and i need the list of subfolders in \\xxxx This code works when i use it with \\xxxx\xx but when I try it with \\xxxx it gives the error
get-childitem : Cannot find path '\\' because it does not exist.
$RootPath = Get-Content -Path "$PSScriptRoot\roots1.txt" $hash = Get-ChildItem -Path $RootPath -Directory -Recurse -force | Group-Object directoryname -AsHashTable -AsString $hash.GetEnumerator() | ForEach-Object { [PSCustomobject]@{Path = $_.value.fullname -join '|'}} | Export-Csv -Path C:\Users\darpan.vedi\Desktop\paths.csv -NoTypeInformation
\\xxxxis not a folder or share - it's a host, and you can't enumerate its contents like a normal folder.