# List of NAS shares to test
$nasShares = @("\\nas-server\share1", "\\nas-server\share2")
# Prompt for user credentials
$credentials = Get-Credential
# Results file
$resultsFile = "C:\NAS_Accessibility_Results.txt"
# Initialize results
$results = @()
# Function to test accessibility
function Test-Accessibility {
param (
[string]$path,
[PSCredential]$credentials
)
try {
# Use New-PSDrive to test the connection
$drive = New-PSDrive -Name TestDrive -PSProvider FileSystem -Root $path -Credential $credentials -ErrorAction Stop
# If the connection is successful, remove the drive and return "Accessible"
Remove-PSDrive -Name TestDrive -Force
return "Accessible"
} catch {
# If there is an error, return "Inaccessible" with the error message
return "Inaccessible: $($_.Exception.Message)"
}
}
# Test each NAS share
foreach ($share in $nasShares) {
$status = Test-Accessibility -path $share -credentials $credentials
$results += "$share: $status"
}
# Write results to file
$results | Out-File -FilePath $resultsFile
# Open results in Notepad
Start-Process notepad.exe $resultsFile
Write-Host "Accessibility test completed. Results saved to $resultsFile"
PowerShell Script test a list of NAS shares accessibility
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment