Search code examples
powershellnas

Reading NAS folders via powershell


Hi :) Here's my problem: I want to see how many subfolders my NAS has. Via Google I found the following:

Get-ChildItem -Path \\<#NASIP#>\ | SELECT Attributes, Name, CreationTime | Format-Table -AutoSize;

I can extend this command so that I know how many (e.g. "8") there are at the end. But now this command does not work as intended. If I use the Pure IP: \\<#NASIP#>\ the following error is displayed:

Get-ChildItem : The path "\\<#NASIP##>\" cannot be found, because it does not exist.

If I now specify a subfolder e.g. pictures: \\<#NASIP#>\pictures

                Attributes Name           CreationTime
                ---------- ----           ------------
System, Directory, Archive xxxxxx         xxxxxxxxxx 15:26:37
        Directory, Archive xxxxxx         xxxxxxxxxx 20:51:17
        Directory, Archive xxxxxx         xxxxxxxxxx 11:35:26
        Directory, Archive xxxxxx         xxxxxxxxxx 21:19:19

the command works without any problems and I get everything output correctly. Does anybody know what this could be?

Greetings Zala


Solution

  • Found the solution. Since the NAS does not share folders but shares, it does not work with Get-ChildItem. As an alternative I now do it via Net view. This works without problems. An example how the command can look like:

    net view \\$target /all | ?{$_ -match 'platte*'} | %{$_ -match '^(.+?)\s+Platte*'|out-null;$matches[1]}
    

    Greetings Zala