Monitor File System - extend the built in UNC monitor
Hi,
I developed a small PowerShell script that monitors the number of files in a folder and returns the total number of files in the root folder, the number of files in all the subfolders, the number of folders in the root of the folder and number of folders in all the subfolders.
In additional, you can filter by file extension.
Because it's powershell, you can easily add filter a specific folder and more.
Remember, PowerShell script run on the collector and not on the server even if in the apply to you select a server.
So or install the collector on the server you want to monitor, or use UNC like \\
Also remember to allow remote PowerShell
The active discovery script is:
$folderspath = '##FolderToMonitor##';
$SearchSExt = 'zip'
$separator = ";"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$array = $folderspath.Split($separator, $option)
$stringcount = $folderspath.Split($separator,2, $option).Count
$folder_id=0
foreach ($folder in $array) {
$folder_id++
$separatorext = "@"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$arrayext = $folder.Split($separatorext, $option)
$folderpath = $arrayext[0]
$SearchSExt = $arrayext[1]
If ($SearchSExt -eq '*' -or $SearchSExt -eq $null)
{
# write out the instance data
Write-Host "OPFID$folder_id##$folderpath##$folderpath";
}
else
{
Write-Host "OPFID$folder_id##$folderpath##$folderpath filter ext $SearchSExt";
}
}
The collector script below and it get parameter as like that
\\MyServer\MyShare\Test1@*;\\MyServer\MyShare\Test2@xml;\\MyServer\MyShare\Test3@zip;\\MyServer\MyShare\Test4@*
This will apply to $folderspath = '##FolderToMonitor##'; if you will use the device properties
So you can specify a list of folders separated by ";" and you can specify the file ext. filter by @
$folderspath = '##FolderToMonitor##';
$separator = ";"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$array = $folderspath.Split($separator, $option)
$stringcount = $folderspath.Split($separator,2, $option).Count
$folder_id=0
foreach ($folder in $array) {
$folder_id++
$separatorext = "@"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$arrayext = $folder.Split($separatorext, $option)
$folderpath = $arrayext[0]
$SearchSExt = $arrayext[1]
If ($SearchSExt -eq '*' -or $SearchSExt -eq $null)
{
$TotalFiles=Get-ChildItem $folderpath -Recurse -File | Measure-Object | %{$_.Count}
$TotalFolders= Get-ChildItem $folderpath -Recurse -Directory | Measure-Object | %{$_.Count}
$TotalFilesInRoot=Get-ChildItem $folderpath -File | Measure-Object | %{$_.Count}
$TotalFoldersInRoot=Get-ChildItem $folderpath -Directory | Measure-Object | %{$_.Count}
}
else
{
$TotalFiles=Get-ChildItem $folderpath -recurse -File -filter *.$SearchSExt | Measure-Object | %{$_.Count}
$TotalFolders= Get-ChildItem $folderpath -Recurse -Directory | Measure-Object | %{$_.Count}
$TotalFilesInRoot=Get-ChildItem $folderpath -File -filter *.$SearchSExt | Measure-Object | %{$_.Count}
$TotalFoldersInRoot=Get-ChildItem $folderpath -Directory | Measure-Object | %{$_.Count}
}
Write-Host "OPFID$folder_id.TotalFiles="$TotalFiles;
Write-Host "OPFID$folder_id.TotalFolders="$TotalFolders;
Write-Host "OPFID$folder_id.TotalFilesInRoot="$TotalFilesInRoot;
Write-Host "OPFID$folder_id.TotalFoldersInRoot="$TotalFoldersInRoot;
}