Powershell - Netapp Create SMB share

$credential = Import-Clixml D:\credentials\ps-credentials.xml # get user + password

$newshares = "D:\Scripts\smb-cdot-shares-.csv"

$prefix = 'pol_np_appl_'

$shares = Get-Content $newshares | where {($_.trim() -ne '') -notlike($_.StartsWith("#"))} # skip empty lines, "# comments"

foreach ($record in $shares)

{

$create = $($record -split ';')[0] # true | false

$cluster = $($record -split ';')[1] # cdot cluster

$vserver = $($record -split ';')[2] # vserver

$volume = $($record -split ';')[3] # volume

$qtree = $($record -split ';')[4] # qtree

$size = $($record -split ';')[5] # disk-limit (soft quota) size

$comment = $($record -split ';')[6] # share comment

$controller = Connect-NcController -Name $cluster -Credential $credential

$exists = get-ncqtree -VserverContext $vserver -Volume $volume -Qtree $qtree # check if qtree already exists

if (($create -eq 'true') -and ($exists.qtree -eq $null))

{

Write-Host "create share '$prefix$qtree$' on $vserver, " -ForegroundColor Green -NoNewline

# add qtree to volume

$nooutput = new-ncqtree -VserverContext $vserver -Volume $volume -Qtree $qtree

# add share to qtree

$nooutput = add-nccifsshare -VserverContext $vserver -Name $prefix$qtree$ -Path /$volume/$qtree -Comment "NP Appl $comment"

# add access based enumeration (ABE) by get existing properties and add ABE

$shareproperties = ((get-nccifsshare -VserverContext $vserver -Name $prefix$qtree$ | select -ExpandProperty shareproperties) + "access_based_enumeration") | select -Unique

$nooutput = Set-NcCifsShare -VserverContext $vserver -Name $prefix$qtree$ -ShareProperties $shareproperties

# add "Authenticated Users" and remove "Everyone"

$nooutput = add-NcCifsShareAcl -VserverContext $vserver -Share $prefix$qtree$ -userorgroup "NT AUTHORITY\Authenticated Users" -permission Full_Control

$nooutput = remove-NcCifsShareAcl -VserverContext $vserver -Share $prefix$qtree$ -userorgroup Everyone

#add quota soft limit

$nooutput = Add-NcQuota -VserverContext $vserver -Path /vol/$volume/$qtree -SoftDiskLimit $size

#resize quota

$QuotaResize = Start-NcQuotaResize -VserverContext $vserver -volume $volume

#$QuotaResize | select -Property JobName,JobStatusCode,Jobid,JobState

Write-Host "jobid = $($QuotaResize.Jobid)." -ForegroundColor Green

$nooutput = Start-Sleep -Seconds 15 # give quota job time to finish

} # end if

else

{

Write-Host "skip to create share '$prefix$qtree$' on $vserver, because " -ForegroundColor DarkYellow -NoNewline

if ($exists.qtree -ne $null)

{ Write-host "it already exists." -ForegroundColor DarkYellow }

else

{ Write-Host "create flag in config file is 'false'." -ForegroundColor DarkYellow }

} # end else

} # end foreach loop