<?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: Script to modify volume automatically in Software Development Kit (SDK) and API Discussions</title>
    <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450959#M3284</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could do something like this...so you have one script which you run with different argument values depending on if you want to turn snapdir on or off and set the command to run the script in the schedule task configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Param(
   [Parameter(Mandatory = $True, HelpMessage = "The state of the snapshot directory for the volume")]
   [ValidateSet("on","off")]
   [String]$Snapdir
)
#'------------------------------------------------------------------------------
#'Set variables.
#'------------------------------------------------------------------------------
$cluster = "192.168.100.10"
$vserver = "svm1"
$volume  = "vol1"
#'------------------------------------------------------------------------------
#'Set the snapdir access value based on the input parameter.
#'------------------------------------------------------------------------------
If($Snapdir -eq "on"){
   $AccessEnabled = $True
}Else{
   $AccessEnabled = $False
}
#'------------------------------------------------------------------------------
#'Enumerate cached credentials and connect to the cluster.
#'------------------------------------------------------------------------------
$credential = (Get-NcCredential -Controller $cluster).Credential
Connect-NcController -Name $cluster -Credential $credential
#'------------------------------------------------------------------------------
#'Update the snapshot directory access for the volume.
#'------------------------------------------------------------------------------
$query = Get-NcVol -Template
Initialize-NcObjectProperty $query VolumeIdAttributes
$query.VolumeIdAttributes.Name = $volume
$query.VolumeIdAttributes.OwningVserverName = $vserver
$attributes = Get-NcVol -Template
$attributes.SnapshotDirectoryAccessEnabled = $True
Update-NcVol -Query $query -Attributes $attributes
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: This assumes that you've cached the credentials to connect to cluster as within the security context of the account that is running the scheduled task using the "Add-NcCredential" cmdlet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However i noticed an issue with the "update-ncvol" cmdlet trying to enable snapdir for older versions of ontap so you would have to use the private REST CLI to run the snapdir command. Which version of ONTAP are you using???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Matt&lt;/P&gt;</description>
    <pubDate>Thu, 22 Feb 2024 02:56:19 GMT</pubDate>
    <dc:creator>mbeattie</dc:creator>
    <dc:date>2024-02-22T02:56:19Z</dc:date>
    <item>
      <title>Script to modify volume automatically</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450410#M3283</link>
      <description>&lt;P&gt;Hi everyone, I need to automatically at 1am make the .snapshot directory available for a backup and hid the .snapshot directory at 3am after the backup. It just 2 simple commands that is required but it can't be made on the ontap so I'm a bit lost of how can I do it. Anyone kind enough to give me a light please?&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 09:42:02 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450410#M3283</guid>
      <dc:creator>leaqui</dc:creator>
      <dc:date>2025-06-04T09:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script to modify volume automatically</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450959#M3284</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could do something like this...so you have one script which you run with different argument values depending on if you want to turn snapdir on or off and set the command to run the script in the schedule task configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Param(
   [Parameter(Mandatory = $True, HelpMessage = "The state of the snapshot directory for the volume")]
   [ValidateSet("on","off")]
   [String]$Snapdir
)
#'------------------------------------------------------------------------------
#'Set variables.
#'------------------------------------------------------------------------------
$cluster = "192.168.100.10"
$vserver = "svm1"
$volume  = "vol1"
#'------------------------------------------------------------------------------
#'Set the snapdir access value based on the input parameter.
#'------------------------------------------------------------------------------
If($Snapdir -eq "on"){
   $AccessEnabled = $True
}Else{
   $AccessEnabled = $False
}
#'------------------------------------------------------------------------------
#'Enumerate cached credentials and connect to the cluster.
#'------------------------------------------------------------------------------
$credential = (Get-NcCredential -Controller $cluster).Credential
Connect-NcController -Name $cluster -Credential $credential
#'------------------------------------------------------------------------------
#'Update the snapshot directory access for the volume.
#'------------------------------------------------------------------------------
$query = Get-NcVol -Template
Initialize-NcObjectProperty $query VolumeIdAttributes
$query.VolumeIdAttributes.Name = $volume
$query.VolumeIdAttributes.OwningVserverName = $vserver
$attributes = Get-NcVol -Template
$attributes.SnapshotDirectoryAccessEnabled = $True
Update-NcVol -Query $query -Attributes $attributes
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: This assumes that you've cached the credentials to connect to cluster as within the security context of the account that is running the scheduled task using the "Add-NcCredential" cmdlet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However i noticed an issue with the "update-ncvol" cmdlet trying to enable snapdir for older versions of ontap so you would have to use the private REST CLI to run the snapdir command. Which version of ONTAP are you using???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Matt&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 02:56:19 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450959#M3284</guid>
      <dc:creator>mbeattie</dc:creator>
      <dc:date>2024-02-22T02:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Script to modify volume automatically</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450961#M3285</link>
      <description>&lt;P&gt;Hi leaqui,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you go, this script will set the "snapdir-access" on or off based on the input variable values. EG:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;PS C:\Scripts\SetSnapdirAccess&amp;gt; .\SetSnapdirAccess.ps1 -Cluster 192.168.100.100 -Vserver svm1 -Volume vol1 -Snapdir on
The ONTAP version running on cluster "192.168.100.100" is "9.12.1P8". Invoking System API
Executed Command: volume modify -vserver svm1 -volume vol1 -snapdir-access true
Updated snapshot directory access on volume "vol1" on vserver "svm1" on cluster "192.168.100.100"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to ensure the PowerShell toolkit is installed. Open an elevated PowerShell prompt as admin and run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Install-Module NetApp.ONTAP&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then open a PowerShell prompt as the Active Directory service account user that you will be running the scheduled task as. EG:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;runas /user:domain\username powershell.exe&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then cache the credentials as the user that will run the scheduled task:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$credential = Get-Credential
Add-NcCredential -Controller 192.168.100.100 -Credential $credential&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you are configuring your scheduled task you set the input parameters. EG:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;powershell.exe C:\Scripts\SetSnapdirAccess\SetSnapdirAccess.ps1 -Cluster 192.168.100.100 -Vserver svm1 -Volume vol1 -Snapdir off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: That you can run the same script to turn it back on again. Just create a second scheduled task and set the -Snapdir parameter value to on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the source code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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]$Vserver,
   [Parameter(Mandatory = $True, HelpMessage = "The volume name")]
   [String]$Volume,
   [Parameter(Mandatory = $True, HelpMessage = "The state of the snapshot directory for the volume")]
   [ValidateSet("on","off")]
   [String]$Snapdir
)
#'------------------------------------------------------------------------------
#'Set the snapdir access value based on the input parameter.
#'------------------------------------------------------------------------------
If($Snapdir -eq "on"){
   $AccessEnabled = $True
}Else{
   $AccessEnabled = $False
}
#'------------------------------------------------------------------------------
#'Enumerate cached credentials for the cluster.
#'------------------------------------------------------------------------------
Try{
   $credential = (Get-NcCredential -Controller $cluster -ErrorAction Stop).Credential
}Catch{
   Write-Warning -Message "Failed enumerating credentials for cluster ""$cluster"""
}
If($Null -eq $credential){
   Write-Warning -Message "The credentials for cluster ""$cluster"" were null. Exiting"
   Exit -1
}
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
Try{
   $connection = Connect-NcController -Name $cluster -Credential $credential -ErrorAction Stop
   $version    = $connection.Version.Split(":")[0].Split(" ")[2].Split(".")
}Catch{
   Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
   Exit -1
}
#'------------------------------------------------------------------------------
#'Set a variable to use the system API if the ONTAP version is &amp;lt; 9.13.
#'------------------------------------------------------------------------------
If(($version[0] -ge 9) -And ($version[1] -ge 13)){
   $useSystemApi = $False
}Else{
   $useSystemApi = $True
}
#'------------------------------------------------------------------------------
#'Update the snapshot directory access for the volume.
#'------------------------------------------------------------------------------
If(-Not($useSystemApi)){
   $query = Get-NcVol -Template
   Initialize-NcObjectProperty $query VolumeIdAttributes
   $query.VolumeIdAttributes.Name = $volume
   $query.VolumeIdAttributes.OwningVserverName = $vserver
   $attributes = Get-NcVol -Template
   $attributes.SnapshotDirectoryAccessEnabled = $True
   Try{
      Update-NcVol -Query $query -Attributes $attributes -ErrorAction Stop
      Write-Host "Updated snapshot directory access on volume ""$Volume"" on vserver ""$Vserver"" on cluster ""$Cluster"""
   }Catch{
      Write-Warning -Message $("Failed updating snapshot directory access on volume ""$Volume"" on vserver ""$Vserver"" on cluster ""$Cluster"". Error " + $_.Exception.Message)
      Exit -1
   }
   Exit 0
}Else{
   Write-Host $("The ONTAP version running on cluster ""$Cluster"" is """ +  ($Version -join ".") + """. Invoking System API")
}
#'------------------------------------------------------------------------------
$command = $("volume modify -vserver $Vserver -volume $Volume -snapdir-access " + $AccessEnabled.ToString().ToLower())
$cmd     = $command.Split(" ")
$api     = $("&amp;lt;system-cli&amp;gt;&amp;lt;args&amp;gt;&amp;lt;arg&amp;gt;" + ($cmd -join "&amp;lt;/arg&amp;gt;&amp;lt;arg&amp;gt;") + "&amp;lt;/arg&amp;gt;&amp;lt;/args&amp;gt;&amp;lt;/system-cli&amp;gt;")
#'------------------------------------------------------------------------------
#'Invoke the API.
#'------------------------------------------------------------------------------
Try{
   $output = Invoke-NcSystemApi -Request $api -ErrorAction Stop
   Write-Host $("Executed Command`: " + $([String]::Join(" ", $command)))
   Write-Host "Updated snapshot directory access on volume ""$Volume"" on vserver ""$Vserver"" on cluster ""$Cluster"""
}Catch{
   Write-Warning -Message $("Failed Executed Command`: " + $([String]::Join(" ", $command)) + ". Error " + $_.Exception.Message)
   Write-Warning -Message "Failed updating snapshot directory access on volume ""$Volume"" on vserver ""$Vserver"" on cluster ""$Cluster"""
   Exit -1
}
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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>Thu, 22 Feb 2024 05:49:30 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Script-to-modify-volume-automatically/m-p/450961#M3285</guid>
      <dc:creator>mbeattie</dc:creator>
      <dc:date>2024-02-22T05:49:30Z</dc:date>
    </item>
  </channel>
</rss>

