-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor_countFiles.ps1
More file actions
109 lines (67 loc) · 1.9 KB
/
monitor_countFiles.ps1
File metadata and controls
109 lines (67 loc) · 1.9 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Kai Osthoff <ko@osthoff.net>
# March, 2020
# Today listening to https://open.spotify.com/playlist/37i9dQZF1DWXDvpUgU6QYl?si=lXw-cBpOQk6P8pFlyyrccQ while coding!
# License
# https://choosealicense.com/licenses/gpl-3.0/
# Parameters: Defaults can be overriden by datto RMM
$MonitorPath = "C:\Users"
$countLimit = 250
$recurseMode = $false
$githubLink = "https://github.com/mspautomation/rmmMonitor_countFiles"
$mspSOP = "https://github.com/mspautomation/rmmMonitor_countFiles/wiki/mspSOP"
# Are there any input from AEM?
if (Test-Path env:\MonitorPath) {
$MonitorPath = $env:MonitorPath
}
if (Test-Path env:\mspSOP) {
$mspSOP = $env:mspSOP
}
if (Test-Path env:\countLimit) {
$countLimit = $env:countLimit
}
if (Test-Path env:\recurseMode) {
$recurseMode = $env:recurseMode
}
# Need in every Script
$aem_alertStart = "<-Start Result->"
$aem_alertEnd = "<-End Result->"
$aem_diagStart = "<-Start Diagnostic->"
$aem_diagEnd = "<-End Diagnostic->"
$alert = $false
if($env:recurseMode -eq $true) {
$count = (Get-ChildItem -Path $MonitorPath -Recurse -Directory | Measure-Object).Count
} else {
$count = (Get-ChildItem -Path $MonitorPath | Measure-Object).Count
}
if($count -gt $countLimit) {
$alert = $true
} else {
$alert = $false
}
#Output Diagnostics
#Write-Output 'Start of AEM Output:'
Write-Output $aem_alertStart
if ($alert -eq $true) {
$aem_alert = "Warning=" + $count + " files in " + $MonitorPath
}
Else {
$aem_alert = "Warning=" + $count + " files in " + $MonitorPath
}
Write-Output $aem_alert
Write-Output $aem_alertEnd
if ($alert -eq $true) {
Write-Output $aem_diagStart
Write-Output ""
Write-Output "`n`n"
Write-Output "SOP: " + $mspSOP +"`n"
Write-Output "Support and more for that genius Component: " + $githubLink
Write-Output $aem_diagEnd
}
if ($alert -eq $true) {
Exit 1
} Else
{
Exit 0
}
#
#