-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup-wallpapers.psm1
51 lines (40 loc) · 1.13 KB
/
cleanup-wallpapers.psm1
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
Add-Type -Assembly System.Drawing
function Clean-Wallpapers {
if($env:WallpapersDirectory -eq $null)
{
write-output 'No wallpapers directory set defaulting'
$env:WallpapersDirectory = 'E:\OneDrive\reddit\wallpapers'
}
write-output ('Cleaning wallpaper directory: ' + $env:WallpapersDirectory)
$wallpapers = get-childitem -path $env:WallpapersDirectory
$currentDateTime = get-date
foreach($wallpaper in $wallpapers)
{
if($wallpaper.Name -eq 'no_image_card.png')
{
remove-item $wallpaper.FullName
continue
}
if($wallpaper.Length -le 1000000)
{
remove-item $wallpaper.FullName
continue
}
$writeDateTime = [datetime]$wallpaper.LastWriteTime
$timespan = $currentDateTime - $writeDateTime
if($timespan.TotalDays -ge 30)
{
remove-item $wallpaper.FullName
continue
}
$image = [Drawing.Image]::FromFile($wallpaper.FullName)
if($image.Width -lt 1920 -or $image.Height -lt 1080)
{
$image.Dispose()
remove-item $wallpaper.FullName
continue
}
$image.Dispose()
}
}
export-modulemember -function Clean-Wallpapers