1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<# .DESCRIPTION Copy the cluster xel files to another directory so that they aren't aged off too soon. .PARAMETER $SourcePath Location of the source files. ie: C:\temp\source .PARAMETER $DestinationPath Location where the source files should be moved to. ie: C:\temp\destination .PARAMETER $FileNamePattern A description of what the file name looks like. Accepts wildcards. ie: "*.xel". .PARAMETER $DaysToRetainDestinationFiles The number of days that the files should stay in the destination folder before being deleted. .NOTES Author: Wayne Sheffield Date: 2016-12-06 Script's Home: ******************************************************************************* MODIFICATION LOG ******************************************************************************* 2016-12-06 WGS Initial Creation. ******************************************************************************* #> param ( [string] $SourcePath, [string] $DestinationPath, [string] $FileNamePattern, [int] $DaysToRetainDestinationFiles ) # Ignore errors when file is locked by another process # $ErrorActionPreference = "SilentlyContinue" # Get the files to copy $SourceFiles = Get-ChildItem $SourcePath | Where-Object {$_.Name -like $FileNamePattern}; # If the file is not in the destination folder, and it's size is > 0, then move it to the destination folder. # This will prevent trying to copy the currently open file. ForEach($File in $SourceFiles) { If (-Not (Test-Path ($File.FullName.Replace($SourcePath, $DestinationPath))) -and ($File.Length -gt 0)) { Move-Item $File.FullName -Destination $DestinationPath -Force } } # Remove files in the Destination Path over 5 days old. Get-ChildItem -Path $DestinationPath | Where-Object {$_.CreationTime -lt (Get-Date).AddDays(-$DaysToRetainDestinationFiles)} | Remove-Item -Force; |