Skip to content

Instantly share code, notes, and snippets.

@irwins
Created July 26, 2016 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save irwins/e291de3b512ca5b88ba33443580d9674 to your computer and use it in GitHub Desktop.
Save irwins/e291de3b512ca5b88ba33443580d9674 to your computer and use it in GitHub Desktop.
<#
Author: I. Strachan
Version:
Version History:
Purpose: OVF for SMBShares
#>
[CmdletBinding()]
Param(
$csvFile = 'DFSnShares.csv'
)
#region Import CSV and saved Credentials
$csvDFSnShares = Import-Csv .\sources\csv\$csvFile -Encoding UTF8 -Delimiter "`t"
$savedCreds = Import-CliXml -Path "${env:\userprofile}\Hash.Cred"
$cred = $savedCreds.'admstrachan'
#endregion
#region
$csvDFSnShares |
ForEach-Object{
#If CIMSession doesn't exist create one
if(!$( Get-CimSession -Name $_.Server -ErrorAction SilentlyContinue)){
$CIMSession = New-CimSession -ComputerName $_.Server -Name $_.Server -Credential $cred
}
else{
#Get CIMSession
$CIMSession = Get-CimSession -Name $_.Server
}
#Test if Share is available
$Share = Get-SmbShare -Name $_.ShareName -CimSession $CIMSession -ErrorAction SilentlyContinue
Describe "SMBShare Operation validation share $($_.ShareName) on $($_.Server)" -Tags 'DFSnShares' {
Context "Verifying share properties on $($_.Server)" {
It "Share Name $($_.ShareName) exists" {
$_.ShareName | Should be $Share.Name
}
It "Share Path $($_.Path) exists"{
$_.Path | Should Be $Share.Path
}
It "$($_.FullAccess) has full Access" {
$FullAccess = Get-SmbShareAccess -CimSession $CIMSession -Name $share.Name | Where-Object{$_.AccessRight -eq 'Full'}
$FullAccess.AccountName.Contains($_.FullAccess) | Should be $true
}
}
}
}
#endregion
#region Remove CimSessions
Get-CimSession | Remove-CimSession
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment