Sunday, 25 October 2015

Applying Volume Comments to cDOT using Data ONTAP PowerShell Toolkit

Applying volume comments is surprisingly fiddly via the Data ONTAP PowerShell Toolkit (I’ve not upgraded from 3.2 - perhaps easier it later releases.) So I created a function to do it and return true/false depending on whether it was successful or not.

The Function Apply-CmVolComment is the interesting bit of the post, and reusable in other scripts/tools - everything beyond is just an example of how to use it.

FUNCTION Apply-CmVolComment{
  $a = Get-NcVol -Template
  $q = Get-NcVol -Template
  Initialize-NcObjectProperty $a VolumeIdAttributes
  Initialize-NcObjectProperty $q VolumeIdAttributes
  $a.VolumeIdAttributes.Comment = $COMMENT
  $q.VolumeIdAttributes.Name = $VOLNAME
  $q.VolumeIdAttributes.OwningVserverName = $SVMNAME
  [Void](Update-NcVol -Attributes $a -Query $q)
  IF((Get-NcVol -Name $VOLNAME -Attributes $a).VolumeIdAttributes.Comment -eq $COMMENT){ RETURN $TRUE }

  Param([String]$ToDisplay,[String]$Color = "WHITE",[String]$LogFile)
  If($ToDisplay){ Write-Host $ToDisplay -ForegroundColor $Color -NoNewLine } else { Write-Host }
  If($LogFile){ $ToDisplay >> $LogFile }

FUNCTION Check-ApplyCmVolComment {
  [Boolean]$Check = Apply-CmVolComment $COMMENT $VOLNAME $SVMNAME
  IF($Check){ Wr ("Applied comment " + '"' + $Comment + '"' + " to volume $Volname on $Svmname") GREEN; Wr }
  ELSE{ Wr ("FAILED to apply comment $Comment to volume $Volname on $Svmname") RED -Log $LOGFILE; Wr }

$Comment = Read-Host "Comment"
$Volume  = Read-Host "Volume "
$Svmname = Read-Host "SVM    "

[Void](Check-ApplyCmVolComment $Comment $Volume $Svmname "Errors.txt")

No comments:

Post a Comment

Note: only a member of this blog may post a comment.