Count Files&Folders with Powershell
- Enis GOKTAY
- 28 Oca 2021
- 1 dakikada okunur
Hello Folks!
Enis is back, : ))
You can find here very very simple Powershell script which counts files and folders and creates an event logs if it is more than number that you specified.
# Created by EnisG 27/01/2021
# for Count Files&Folders
$Paths = @(“C:\enisgoktay\test”, “d:\powershellscripts”, “e:\sap”); $source=“DosyaSayisi”
if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false)
{
[System.Diagnostics.EventLog]::CreateEventSource($source, “Application”)
}
Foreach ($path in $Paths)
{
if (Test-Path -Path $path)
{
$file_count = (Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue).Count
if ($file_count -gt 10000 )
{
Write-EventLog -LogName Application -Source DosyaSayisi -EntryType Error -Message “$path klasor icinde $file_count tane dosya vardir.” -EventId 221
}
}
}
Comments