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{
Param([String]$COMMENT,[String]$VOLNAME,[String]$SVMNAME)
$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 }
ELSE{ RETURN $FALSE }
}
FUNCTION
Wr {
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 {
Param([String]$COMMENT,[String]$VOLNAME,[String]$SVMNAME,[String]$LOGFILE)
[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")
Comments
Post a Comment