2019-10-29 04:01:38 -04:00
|
|
|
Import-IcingaLib core\tools;
|
|
|
|
|
|
|
|
|
|
function Get-IcingaDirectoryAll()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Path,
|
|
|
|
|
[array]$FileNames,
|
|
|
|
|
[bool]$Recurse,
|
2019-10-30 12:50:07 -04:00
|
|
|
[string]$YoungerThan,
|
2019-10-31 04:43:49 -04:00
|
|
|
[string]$OlderThan,
|
|
|
|
|
[string]$FileSizeGreaterThan,
|
|
|
|
|
[string]$FileSizeSmallerThan
|
2019-10-29 04:01:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($Recurse -eq $TRUE) {
|
|
|
|
|
$DirectoryData = Get-ChildItem -Recurse -Path $Path -Include $FileNames;
|
|
|
|
|
} else {
|
|
|
|
|
$DirectoryData = Get-ChildItem -Path $Path -Include $FileNames;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 12:50:07 -04:00
|
|
|
if ([string]::IsNullOrEmpty($OlderThan) -eq $FALSE -And [string]::IsNullOrEmpty($YoungerThan) -eq $FALSE) {
|
2019-10-31 04:43:49 -04:00
|
|
|
$OlderThan = Set-NumericNegative (ConvertTo-Seconds $OlderThan);
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -lt (Get-Date).AddSeconds($OlderThan)})
|
|
|
|
|
$YoungerThan = Set-NumericNegative (ConvertTo-Seconds $YoungerThan);
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -gt (Get-Date).AddSeconds($YoungerThan)})
|
2019-10-30 12:50:07 -04:00
|
|
|
} elseif ([string]::IsNullOrEmpty($OlderThan) -eq $FALSE) {
|
2019-10-31 04:43:49 -04:00
|
|
|
$OlderThan = Set-NumericNegative (ConvertTo-Seconds $OlderThan);
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -lt (Get-Date).AddSeconds($OlderThan)})
|
2019-10-30 12:50:07 -04:00
|
|
|
} elseif ([string]::IsNullOrEmpty($YoungerThan) -eq $FALSE) {
|
2019-10-31 04:43:49 -04:00
|
|
|
$YoungerThan = Set-NumericNegative (ConvertTo-Seconds $YoungerThan);
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.LastWriteTime -gt ((Get-Date).AddSeconds($YoungerThan))})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([string]::IsNullOrEmpty($FileSizeGreaterThan) -eq $FALSE) {
|
|
|
|
|
$FileSizeGreaterThanValue = (Convert-Bytes $FileSizeGreaterThan -Unit B).value
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeGreaterThanValue})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([string]::IsNullOrEmpty($FileSizeSmallerThan) -eq $FALSE) {
|
|
|
|
|
$FileSizeSmallerThanValue = (Convert-Bytes $FileSizeSmallerThan -Unit B).value
|
|
|
|
|
$DirectoryData = ($DirectoryData | Where-Object {$_.Length -gt $FileSizeSmallerThanValue})
|
2019-10-29 04:01:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $DirectoryData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-IcingaDirectory()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Path,
|
|
|
|
|
[array]$FileNames
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$DirectoryData = Get-ChildItem -Include $FileNames -Path $Path;
|
|
|
|
|
|
|
|
|
|
return $DirectoryData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-IcingaDirectoryRecurse()
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Path,
|
|
|
|
|
[array]$FileNames
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$DirectoryData = Get-ChildItem -Recurse -Include $FileNames -Path $Path;
|
|
|
|
|
|
|
|
|
|
return $DirectoryData;
|
|
|
|
|
}
|