Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-LongFileName
- {
- #region Comment Based Help [CBH]
- # trailing blank line required by CBH
- <#
- .SYNOPSIS
- Gets the names of files that are longer than specified.
- .DESCRIPTION
- Uses Robocopy [with /L to avoid any changes] to get file names that are longer than specified.
- Scans the entire tree starting at the $Source location.
- Returns [a] $Null [no files]
- [b] a string [one file]
- [c] an array of strings [two or more files]
- .EXAMPLE
- Get-LongFileName -Source C:\temp
- Scans the directory tree starting at C:\temp.
- Returns any file names that are longer than the default of 250 characters.
- .EXAMPLE
- Get-LongFileName -Source C:\temp -MaxFQFN_Length 90
- Scans the directory tree starting at C:\temp.
- Returns any file names that are longer than 90 characters.
- .NOTES
- Version = 2017-02-23_-_22-27
- Robocopy Documentation
- - https://technet.microsoft.com/en-us/library/cc733145
- #>
- # leading blank line required by CBH
- #endregion
- #region Parameters
- [CmdletBinding ()]
- [OutputType ([string[]])]
- Param (
- # Directory to start scanning the tree.
- [Parameter (
- Mandatory,
- Position = 0
- )]
- [ValidateScript ({Test-Path $_})]
- [string]
- $Source,
- # Longest allowed Fully Qualified File Name length.
- [Parameter (
- Position = 1
- )]
- [ValidateRange (0, 250)]
- [int]
- $MaxFQFN_Length = 200
- )
- #endregion
- # giving robocopy a REAL destination here makes it include it as a source.
- # leaving it off makes it complain about not having a destination.
- # that disagrees with the docs. i have no idea why.
- $Destination = "$env:Temp\FolderThatBetterNotBeThere"
- #region Robocopy parameter list
- <#
- source :: Source Directory (drive:\path or \\server\share\path).
- destination :: Destination Dir (drive:\path or \\server\share\path).
- /S :: copy Subdirectories, but not empty ones.
- /XJ :: eXclude Junction points. (normally included by default).
- /R:n :: number of Retries on failed copies: default 1 million.
- /W:n :: Wait time between retries: default is 30 seconds.
- /L :: List only - don't copy, timestamp or delete any files.
- /FP :: include Full Pathname of files in the output.
- /NS :: No Size - don't log file sizes.
- /NC :: No Class - don't log file classes.
- /NDL :: No Directory List - don't log directory names.
- /NP :: No Progress - don't display percentage copied.
- /NJH :: No Job Header.
- /NJS :: No Job Summary.
- #>
- #endregion
- $RC_Params = ($Source, $Destination) + "/S /XJ /R:0 /W:0 /L /FP /NS /NC /NDL /NP /NJH /NJS".Split(' ')
- $RC_FileList = robocopy $RC_Params |
- ForEach-Object {$_.Trim()} |
- Where-Object {$_.Length -gt $MaxFQFN_Length} |
- Sort-Object -Property Length
- return $RC_FileList
- } # end of function
- Get-LongFileName -Source $env:TEMP -MaxFQFN_Length 50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement