PoshCode Logo PowerShell Code Repository

Get-NaCifs by glnsize 35 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/924"></script>download | new post

Get detailed information on every CIFS share on a NetApp Filer. Function requires the NetApp Manage OnTap SDK 3.5.
~Glenn

  1. # Glenn Sizemore www . Get-Admin . Com
  2. # Requires the NetApp OnTap SDK v3.5
  3. #
  4. # Will connect to the destination Filer and retrieve detailed information on every
  5. # Cifs share.  This function will not retrieve permissions.
  6. #
  7. # Usage:
  8. # Connect to the filler
  9. # $Filer = 'TOASTER'
  10. # $NetApp = New-Object NetApp.Manage.NaServer($filer,1,0)
  11. # $NetApp.SetAdminUser(UserName,Password)
  12. #
  13. # Call the function
  14. # Get-NaCifs -Server $NetApp
  15. Function Get-NaCifs {
  16.     Param(
  17.         [NetApp.Manage.NaServer]$Server
  18.     )
  19.     Process {
  20.         # Establish a connection and prepair to iterate through all shares.
  21.         $NaElement = New-Object NetApp.Manage.NaElement("cifs-share-list-iter-start")
  22.         $results = $Server.InvokeElem($naelement)
  23.         $Tag = $results.GetChildContent("tag")  
  24.         $RecordReturned = $results.GetChildContent("records")
  25.        
  26.         $processing=$true
  27.         $increment = 50 #How many records should we process at a time
  28.         # Loop until we get all shares
  29.         While ($processing) {
  30.             $NaElement = New-Object NetApp.Manage.NaElement("cifs-share-list-iter-next")
  31.             $NaElement.AddNewChild("maximum",$increment)
  32.             $NaElement.AddNewChild("tag",$Tag)
  33.             $results = $Server.InvokeElem($naelement)
  34.             $RecordReturned = $results.GetChildContent("records")
  35.             IF ($RecordReturned -eq 0) {
  36.                 break
  37.             } else {
  38.                 Foreach ($share in $results.GetChildByName("cifs-shares").GetChildren()) {
  39.                     $S = "" | Select @{
  40.                         N='Name'
  41.                         E={$share.GetChildContent("share-name")}
  42.                     }, @{
  43.                         N='Path'
  44.                         E={$share.GetChildContent("mount-point")}
  45.                     }
  46.                     # From here on out we'll use add-member because default shares
  47.                     # Won't contain any of these properties.
  48.                     switch($share) {
  49.                         {$_.GetChildByName("caching")}
  50.                             {
  51.                                 $S|Add-Member 'NoteProperty' 'Caching' $_.GetChildContent("caching")
  52.                             }
  53.                         {$_.GetChildByName("description")}
  54.                             {
  55.                                 $S|Add-Member 'NoteProperty' 'Description' $_.GetChildContent("description")
  56.                             }
  57.                         {$_.GetChildByName("dir-umask")}
  58.                             {
  59.                                 $S|Add-Member 'NoteProperty' 'DirUmask' $_.GetChildContent("dir-umask")
  60.                             }
  61.                         {$_.GetChildByName("file-umask")}
  62.                             {
  63.                                 $S|Add-Member 'NoteProperty' 'FileUmask' $_.GetChildContent("file-umask")
  64.                             }
  65.                         {$_.GetChildByName("forcegroup")}
  66.                             {
  67.                                 $S|Add-Member 'NoteProperty' 'Forcegroup' $_.GetChildContent("forcegroup")
  68.                             }
  69.                         {$_.GetChildByName("is-access-based-enum")}
  70.                             {
  71.                                 $S|Add-Member 'NoteProperty' 'ABE' $true
  72.                             }
  73.                         {$_.GetChildByName("is-symlink-strict-security")}
  74.                             {
  75.                                 if ($_.GetChildContent("is-symlink-strict-security") -eq "false") {
  76.                                     $S|Add-Member 'NoteProperty' 'SymlinkStrictSecurity' $False
  77.                                 }
  78.                             }
  79.                         {$_.GetChildByName("is-vol-offline")}
  80.                             {
  81.                                 IF ($_.GetChildContent("is-vol-offline") -eq "true") {
  82.                                     $S|Add-Member 'NoteProperty' 'VolOffline' $true
  83.                                 }
  84.                             }
  85.                         {$_.GetChildByName("is-vscan")}
  86.                             {
  87.                                 IF ($_.GetChildContent("is-vscan") -eq "true") {
  88.                                     $S|Add-Member 'NoteProperty' 'VirusScanOnOpen' $True
  89.                                 }
  90.                             }
  91.                         {$_.GetChildByName("is-vscanread")}
  92.                             {
  93.                                 IF ($_.GetChildContent("is-vscanread") -eq "true") {
  94.                                     $S|Add-Member 'NoteProperty' 'VirusScanOnRead' $True
  95.                                 }
  96.                                
  97.                             }
  98.                         {$_.GetChildByName("is-widelink")}
  99.                             {
  100.                                 IF ($_.GetChildContent("is-widelink") -eq "true") {
  101.                                     $S|Add-Member 'NoteProperty' 'WideLink' $True
  102.                                 }
  103.                             }
  104.                         {$_.GetChildByName("maxusers")}
  105.                             {
  106.                                 $S|Add-Member 'NoteProperty' 'MaxUsers' $_.GetChildContent("maxusers")
  107.                             }
  108.                         {$_.GetChildByName("umask")}
  109.                             {
  110.                                 $S|Add-Member 'NoteProperty' 'Umask' $_.GetChildContent("umask")
  111.                             }
  112.                     }
  113.                     Write-Output $S
  114.                 }
  115.             }
  116.         }
  117.         $NaElement = New-Object NetApp.Manage.NaElement("cifs-share-list-iter-end")
  118.         $NaElement.AddNewChild("tag",$Tag)
  119.         [VOID]$Server.InvokeElem($naelement)
  120.     }
  121. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me