问题
I have found a cmdlet that returns all files regardless of path size. I was wondering if there was an equivalent command that got all the folders regardless of path size?
Get-FolderItem combines robocopy and powershell to return all files even those with the path greater than 260.
Is there anyway to get all the folders in the fileshare
回答1:
Get-FolderItem
uses the robocopy
switch /NDL
to exclude directories from the log output, which it uses to grab the file info. It also avoids empty folders by using the /S
switch to recurse rather than /E
Simply change the $params
variable from:
$params.AddRange(@("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0"))
to
$params.AddRange(@("/L","/E","/NJH","/BYTES","/FP","/NC","/NFL","/TS","/XJ","/R:0","/W:0"))
Now, Robocopy will list directories, rather than files. Since the output for directories is a little different from files, you'll have to change the parsing logic a bit as well.
Change
If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property @{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
Length = [int64]$matches.Size
LastWriteTime = [datetime]$matches.Date
Extension = $matches.fullname -replace '.*\.(.*)','$1'
FullPathLength = [int] $matches.FullName.Length
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
}
to
If ($_.Trim() -match "^(?<Children>\d+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property @{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
}
And that should do it
来源:https://stackoverflow.com/questions/32423513/get-folderitem-version-to-get-all-folders