Simulating your Clustered ONTAP Environment: Part 5 - Generating Folder Structure for CIFS Shares

If we’re going to set up our CIFS shares in the lab like they are in production, we need the folder structure the CIFS shares use to exist, otherwise like for like creation will fail. And here is how we do it.

i) Get the CIFS Share Paths from Clustered Data ONTAP

Run these commands from the Clustershell ::>

rows 0
set -showseparator "#"
cifs share show -vserver VSERVERNAME -fields path

Copy and paste into Excel using the ‘Text Import Wizard’ and # as a delimiter. Then we take all the paths from the paths column and put into a file called say Paths.TXT.

ii) Processing the Paths Using PowerShell

It is not possible to create folders using the Clustershell, but, this nifty bit of code allows us to create folders using PowerShell and the Data ONTAP PowerShell Toolkit (which leverages the API’s). Save as say CifsShareFolderBuilder.ps1 and run with the Paths.TXT file in the same folder:

## CifsShareFolderBuilder.ps1 ##
"<<<< Cifs Folder Structure Builder >>>>"
$filename = Read-Host "Filename "
$cluster  = Read-Host "Cluster  "
">>>> Enter Cluster $cluster credentials <<<<"
$Cred     = New-Object System.Management.Automation.PsCredential($(Read-Host "Adm. User"),$(Read-Host "Adm. Pass" -AsSecureString))
$vserver  = Read-Host "Vserver  "

Import-Module DataONTAP
$content = Get-Content $filename
"Connecting ..."
Connect-NcController -Name $cluster -Credential $Cred

Foreach ($line in $content){

Write-Host "." -NoNewLine
$split = $line.split("/")
$count = $split.count
If($count -gt 1){

$level = "/vol"
$i = 1
while ($i -lt $count){

Write-Host "." -NoNewLine
$level += "/" + $split[$i]
New-NcDirectory -Path $level -VserverContext $Vserver -Permission 777 -ErrorAction SilentlyContinue
$i++                

}
}
}

Note: The path needs to include /vol even if the volumes are only mounted to / (not using /vol). The above script is designed for environments not using/not mounting via the vol folder in the SVM rootvol, and will need a minor modification to work where volumes are mounted via /vol (like $count -gt 2, $i = 2).

Comments