Skip to content

Instantly share code, notes, and snippets.

@AspenForester
Created June 25, 2018 16:04
Show Gist options
  • Save AspenForester/356cd026fcaa1ec817348aca526f72a3 to your computer and use it in GitHub Desktop.
Save AspenForester/356cd026fcaa1ec817348aca526f72a3 to your computer and use it in GitHub Desktop.
Describe "FileServer Shares" {
$FileServers = Import-PowerShellDataFile "H:\HennRepos\InfrastructureTesting\Diagnostics\simple\demodata.psd1"
Foreach ($Node in $FileServers.AllNodes)
{
Context "$($Node.NodeName)" {
# It might be desirable to ensure there is a DNS record for the server before even bothering to try and ping it
# I think I would still do the ping, let it fail and let that cause all of the share tests to be skipped.
$PingResult = Test-Connection -ComputerName $Node.NodeName -Quiet -Count 1
It "Server responds to Ping" {
$PingResult | Should Be $true
}
$ToSkip = -not $PingResult
$cs = New-CimSession -ComputerName $Node.NodeName
Foreach ($Share in $node.Shares)
{
$Result = Get-SmbShare -CimSession $cs -Name $Share.ShareName -ErrorAction SilentlyContinue
It "Share $($Share.ShareName) Exists" {
$Result | Should -not -be $null
} -Skip:$ToSkip
It "Share $($Share.ShareName) refers to $($Share.SharePath)" {
$Result.Path | Should be $($Share.SharePath)
} -Skip:$ToSkip
It "Share $($Share.ShareName) Description is '$($Share.ShareDesc)'" {
$Result.Description | Should -be $Share.ShareDesc
}
It "Share $($Share.ShareName) is reachable" {
Test-path -Path "\\$($Node.NodeName)\$($Share.ShareName)\*" | Should be $true
} -Skip:$ToSkip
}
$cs | Remove-CimSession
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment