Hi Team,
Please help me with a new request where Shared folder available space needs to monitor on file server. We are already doing folder accessible and existing monitoring via below PowerShell script. Please help me with idea or help me to modify script so that it can retrieve the data for folder available space.
# Specify the path to the shared folder you want to check
$sharedFolderPath = "\\wux2000.wux.pacific.firmenich.com\Plant_Automation\Prod\MES_Transfer"
# Function to check if a folder exists
function Test-SharedFolder {
param([string]$folderPath)
if (Test-Path $folderPath -PathType Container) {
return $true
} else {
return $false
}
}
# Check if the shared folder exists
if (Test-SharedFolder -folderPath $sharedFolderPath) {
Write-Host "Message:'$sharedFolderPath' exists."
Write-Host "`n"
# Optional: Test folder accessibility by attempting to list its contents
try {
$folderItems = Get-ChildItem -Path $sharedFolderPath -ErrorAction Stop
Write-Host "Message: Shared folder is accessible."
Write-Host "Statistic: 0"
} catch {
Write-Host "Message: Shared folder exists but is not accessible: $_"
Write-Host "Statistic: 1"
# Optionally handle the error, e.g., send an email notification
}
} else {
Write-Host "Message: Shared folder '$sharedFolderPath' does not exist or is inaccessible."
Write-Host "Statistic: 2"
# Optionally handle the case where the folder does not exist, e.g., send an alert
}