Get-Childitem list only UNC of specific subfolders? RRS feed

  • Question

  • Hi,

    I'm making a health check script which checks software folders on a file share.
    F.e. is there documentation in the folder, is name convention use correctly etc.

    Therefore I would like to have the full path of certain subfolders in a variable.
    F.e. $share = \\share\software\application\applicationversion\
    This $share contains subfolders with 1.Package, 2.Documentation etc
    $Fullpath would then contain 

    This command works but gives ALL unc paths whereas I would need ONLY level 4

    Get-ChildItem -Path $share -Recurse -Depth 4  | Select-Object  pspath | Convert-Path

    So only \\share\software\application\applicationversion\ should be shown in the result
    and not \\share\software\

    Hope this is clear

    Please advise.

    Jan Hoedt

    Saturday, January 7, 2017 8:55 PM


  • Here is a way to do that:

    Get-ChildItem -Path \\alpha\d$ -Recurse -Depth 4 -Directory  |
        ?{($_.Fullname -split '\\').count -eq 8}|
        select -expand fullname

    To get the files:

    Get-ChildItem -Path \\alpha\d$ -Recurse -Depth 4 -Directory  |
        ?{($_.Fullname -split '\\').count -eq 8}|
        Get-ChildItem -File


    Saturday, January 7, 2017 9:32 PM