Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Forked from anonymous/gist:93c9fa41bef0253096bc08bf9518e301
Last active April 8, 2018 01:35
Show Gist options
  • Save Jaykul/2af4f07807f004a0b6811733b0a61dd6 to your computer and use it in GitHub Desktop.
Save Jaykul/2af4f07807f004a0b6811733b0a61dd6 to your computer and use it in GitHub Desktop.
Gists can have multiple files, and if you set the extension, they get syntax highlighting
Import-Module "D:\Coding\PowerShell\Modules\remove-OldFiles.psm1"
remove-OldFiles -Path 'D:\Coding' -ExcludeFolders "Bootstrap Learning","PowerShell","Waaah!"
#the folder Waaah! dont exists in the Folder mentioned above. so in the PSM there is a write-Host line to display this error. but i dont see it when i call the function from the ps1 script.
Function Remove-OldFiles{
param(
[int] $DaysToRemove,
[string[]] $ExcludeFolders,
[string] $Path
)
if(Test-Path $Path){
foreach($ExcludeFolder in $ExcludeFolders){
if(!(Test-Path (Join-Path $Path $ExcludeFolder))){
Write-Host "$ExcludeFolder was not found on the Path $Path"
break # This will break out of the foreach loop, not processing the other ExcludeFolders
} else {
# TODO ...
}
}
$SubFolders = gci -Recurse -Path $Path -Filter $ExlcudeFolders
}else{
Write-Host "Specified path $Path not found"
}
}
Export-ModuleMember -Function Remove-OldFiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment