NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

Microsoft Virtualization Discussions

How to use Powershell to set the snapshot -snaplock-expiry-time ? Thanks!

ACWCalvinWong
2,873 Views
cluster1> volume snapshot create -vserver vs1 -volume vol1 -snapshot snap1 -snaplock-expiry-time "11/10/2022 09:00:00"

Example CLI as above I want to do it in Powershell way, thanks! 

1 ACCEPTED SOLUTION

TzwaynY
2,243 Views

Hey there, there is no native function in the Powershell Module atm. You have todo it via API. This is how I do it:

$VOLUMEURL = "https://NETAPPURL/api/storage/volumes/VOLUMEUUID/snapshots/SNAPSHOTUUID"
$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$PAYLOAD = @{
  "snaplock_expiry_time" = "2069-06-04T19:00:00+00:00" #Edit this to the desired expiration
} | ConvertTo-Json

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method Patch -Body $PAYLOAD -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

 

Please refer to the post I did prior to this:

https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Why-doesn-t-Set-NcSnapshotSnaplockExpTime-set-the-snapshot-snaplock-expiry/m-p/44...

 

Best regards

Kai

View solution in original post

1 REPLY 1

TzwaynY
2,244 Views

Hey there, there is no native function in the Powershell Module atm. You have todo it via API. This is how I do it:

$VOLUMEURL = "https://NETAPPURL/api/storage/volumes/VOLUMEUUID/snapshots/SNAPSHOTUUID"
$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$PAYLOAD = @{
  "snaplock_expiry_time" = "2069-06-04T19:00:00+00:00" #Edit this to the desired expiration
} | ConvertTo-Json

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method Patch -Body $PAYLOAD -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

 

Please refer to the post I did prior to this:

https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Why-doesn-t-Set-NcSnapshotSnaplockExpTime-set-the-snapshot-snaplock-expiry/m-p/44...

 

Best regards

Kai

Public