<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: PS script: New-NcExportRule giving rule index always first number in ONTAP Rest API Discussions</title>
    <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437034#M334</link>
    <description>&lt;P&gt;It is testing and working fine. Thank you&amp;nbsp; for quick help Matt.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Aug 2022 04:57:03 GMT</pubDate>
    <dc:creator>ansible_netapp_Provision</dc:creator>
    <dc:date>2022-08-01T04:57:03Z</dc:date>
    <item>
      <title>PS script: New-NcExportRule giving rule index always first number</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437030#M332</link>
      <description>&lt;P&gt;When we execute export policy rule create through CLI, it always create "rule index" last number which is good and it should but when i did same using PS ,&amp;nbsp;"rule index" taking first number which is not needed. What is wrong here with PS? how can i solve it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;New-NcExportRule&lt;/SPAN&gt; &lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;ClientMatch &lt;/SPAN&gt;&lt;SPAN&gt;"server1"&amp;nbsp;&lt;/SPAN&gt; &lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;ReadOnlySecurityFlavor &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;sys&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt; &lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;ReadWriteSecurityFlavor &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;sys&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Jun 2025 09:58:10 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437030#M332</guid>
      <dc:creator>ansible_netapp_Provision</dc:creator>
      <dc:date>2025-06-04T09:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: PS script: New-NcExportRule giving rule index always first number</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437032#M333</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Index parameter of the "New-NcExportRule" CmdLet will assign the next "available" value, that is not necessarily the next concurrent index rule. To ensure the rule index is incremented you need to apply some programmatic logic if you don't want to accept the defaults. See the following example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Syntax:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;PS C:\&amp;gt; $credential = Get-Credential -Credential admin
PS C:\&amp;gt; .\AddExportRule.ps1 -Cluster cluster1.testlab.local -VserverName vserver2 -VolumeName nfs_data_001 -ClientMatch "192.168.108.0/24" -Credential $credential
Connected to cluster "cluster1.testlab.local" as user "admin"
Enumerated Volume "nfs_data_001" on vserver "vserver2"
Enumerate next concurrent export rule index "8" for policy "default" on vserver "vserver2"
Added export rule index "8" for clientmatch "192.168.108.0/24" to policy "default" for volume "nfs_data_001" on vserver "vserver2"&lt;/LI-CODE&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Source Code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The vserver name")]
   [String]$VserverName,
   [Parameter(Mandatory = $True, HelpMessage = "The volume name")]
   [String]$VolumeName,
   [Parameter(Mandatory = $True, HelpMessage = "The IP Address or IPv4 CIDR address")]
   [String]$ClientMatch,
   [Parameter(Mandatory = $False, HelpMessage = "The Read-Only rule type")]
   [ValidateSet("any","none","never","krb5","krb5i","krb5p","ntlm","sys")]
   [String]$RoRule="any",
   [Parameter(Mandatory = $False, HelpMessage = "The Read-Write rule type")]
   [ValidateSet("any","none","never","krb5","krb5i","krb5p","ntlm","sys")]
   [String]$RwRule="any",
   [Parameter(Mandatory = $False, HelpMessage = "The Protocol type")]
   [ValidateSet("any","cifs","flexcache","nfs","nfs2","nfs3","nfs4")]
   [String]$Protocol="nfs3",
   [Parameter(Mandatory = $True, HelpMessage = "The Credentials to authenticate to the cluster")]
   [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
Try{
   Connect-NcController -Name $Cluster -HTTPS -Credential $Credential -ErrorAction Stop | Out-Null
   Write-Host $("Connected to cluster ""$Cluster"" as user """ + $Credential.UserName + """")
}Catch{
   Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Enumerate the volume and export policy assigned to the volume.
#'------------------------------------------------------------------------------
Try{
   $volume = Get-NcVol -Name $VolumeName -Vserver $VserverName -ErrorAction Stop
   Write-Host "Enumerated Volume ""$VolumeName"" on vserver ""$VserverName"""
}Catch{
   Write-Warning -Message $("Failed enumerating volume ""$VolumeName"" on vserver ""$VserverName"". Error " + $_.Exception.Message)
   Break;
}
[String]$policy = $volume.VolumeExportAttributes.Policy
#'------------------------------------------------------------------------------
#'Increment the export policy rule index.
#'------------------------------------------------------------------------------
Try{
   [Int]$nextIndex = $(Get-NcExportRule -Vserver $VserverName -Policy $policy -ErrorAction Stop | Select-Object -ExpandProperty RuleIndex -Last 1) + 1
   Write-Host "Enumerate next concurrent export rule index ""$nextIndex"" for policy ""$policy"" on vserver ""$VserverName"""
}Catch{
   Write-Warning -Message $("Failed enumerating rule index for policy ""$policy"" on volume ""$VolumeName"" on vserver ""$VserverName"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Add the export policy rule.
#'------------------------------------------------------------------------------
Try{  
   New-NcExportRule -Policy $policy -ClientMatch $ClientMatch -Protocol $Protocol -ReadOnlySecurityFlavor $RoRule -ReadWriteSecurityFlavor $RwRule -VserverContext $VserverName -RuleIndex $nextIndex -ErrorAction Stop
   Write-Host "Added export rule index ""$nextIndex"" for clientmatch ""$ClientMatch"" to policy ""$policy"" for volume ""$VolumeName"" on vserver ""$VserverName"""
}Catch{
   Write-Warning -Message $("Failed adding export rule for clientmatch ""$ClientMatch"" to policy ""$policy"" for volume ""$VolumeName"" on vserver ""$VserverName"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;Hope that helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Matt&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 03:21:25 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437032#M333</guid>
      <dc:creator>mbeattie</dc:creator>
      <dc:date>2022-08-01T03:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: PS script: New-NcExportRule giving rule index always first number</title>
      <link>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437034#M334</link>
      <description>&lt;P&gt;It is testing and working fine. Thank you&amp;nbsp; for quick help Matt.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 04:57:03 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Rest-API-Discussions/PS-script-New-NcExportRule-giving-rule-index-always-first-number/m-p/437034#M334</guid>
      <dc:creator>ansible_netapp_Provision</dc:creator>
      <dc:date>2022-08-01T04:57:03Z</dc:date>
    </item>
  </channel>
</rss>

