This is something I knocked up over the weekend. I needed
a PowerShell script that brings back from a Vserver/SVM, a list volumes and
their qtrees, whether quotas were turned on for those volumes, and - for those
volumes with quotas enabled - how much disk used per qtree/volume (the volumes/qtrees
have tracking quotas/enforced hard disk limits). The intention for the future
is that this information will be used to produce a spreadsheet, so returning
the information as an array we can manipulate later was desired.
Example Output:
PS
C:\> GetVerverQuotaInfoOutput PRICLU1V1
Vserver
# Volume # Qtree # Volume Quota State # Disk Used (KB)
PRICLU1V1
# test # # off #
PRICLU1V1
# v_PKD # q_PKD_Other # on # 20920
PRICLU1V1
# v_PKD # # on #
PRICLU1V1
# v_PKD # q_PKD_PDF # on # 30912
PRICLU1V1
# v_TEST01 # q_disk_limit # off #
PRICLU1V1
# v_TEST01 # q_file_limit # off #
PRICLU1V1
# v_TEST01 # # off #
The Script:
Note: Formatted for
blogger.
#######################################################################
# Getting Quota Information from Clustered Data ONTAP with
PowerShell #
#
=================================================================== #
#######################################################################
#############################################################################
# This function returns an X,Y array of: #
# "Vserver # Volume # Qtree # Volume Quota State # Disk
Used (KB)" #
# Requires Vserver/SVM Name as an argument. #
# If the script is saved as quotaInfo.ps1, the function can be
loaded with: #
# PS C:> . .\quotaInfo.ps1
#
# First you will need to connect to a cluster, then run: #
# PS C:> $output = GetVserverQuotaInfo {SVM/Vserver
Name} #
# The function's $output is an array. #
# A simple output display function is also included, run: #
# PS C:> GetVserverQuotaInfoOutput SVM {SVM/Vserver
Name} #
#############################################################################
function
GetVserverQuotaInfo { # args[0] = vservername
$vserverName
= $args[0]
# Find the Vserver RootVol
$attribute
= Get-NcVserver -Template
$attribute.RootVolume
= ""
$vserver
= Get-NcVserver -Attributes $attribute -VserverContext $vserverName
$rootVol
= $vserver.RootVolume
# Get all the Qtrees
$attribute
= Get-NcQtree -Template
$attribute.volume
= ""
$attribute.qtree
= ""
$qtrees
= Get-NcQtree -Attributes $attribute -VserverContext $vserverName
$tableMaxRows
= $qtrees.count
# Make an X,Y output array
$outputArray
= New-Object 'object[,]' 5,$tableMaxRows
# Define attribute templates
$quotAttr
= Get-NcQuotaStatus -Template
$quotAttr.status
= ""
$quotaRepAtt
= Get-NcQuotaReport -Template
$quotaRepAtt.DiskUsed
= ""
$volAttr
= Get-NcVol -Template
Initialize-NcObjectProperty
-object $volAttr -name VolumeIdAttributes
$volAttr.VolumeIdAttributes.type
= ""
# y is the row number
$y
= 0
# Go through all the qtres
foreach
($qtree in $qtrees){
# Find the volume type (i.e. read-write or not)
$volType
= Get-NcVol -Attributes $volAttr -Volume $qtree.volume -VserverContext $vserverName
# We're not interested in SVM rootvols or non-read-write vols
if
(($qtree.volume -ne $rootvol) -and ($volType.VolumeIdAttributes.Type -eq
"rw")){
# Construct Output Array
$outputArray[0,$y] =
$vserverName
$outputArray[1,$y] =
$qtree.volume
$outputArray[2,$y] =
$qtree.qtree
$quotaOnOff
= (Get-NcQuotaStatus -Attributes $quotAttr -Volume $qtree.volume
-VserverContext $vserverName).status
$outputArray[3,$y] =
$quotaOnOff
# If Quotas is not turned on for the volume, there is no Quota
Report info!
if
($quotaOnOff = "on"){
$quotaReport
= Get-NcQuotaReport -Attributes $quotaRepAtt -Volume $qtree.volume -Qtree
$qtree.qtree -VserverContext $vserverName
$outputArray[4,$y] =
$quotaReport.DiskUsed
}
# Increment Rows
$y++
}
# END of if (($qtree...
}
# END of foreach ($qtree...)
# Returns outputArray
,
$outputArray
}
# END of function GetVserverQuotaInfo
##########################################################
# This function produces a simple display output for the #
# GetVserverQuotaInfo function #
##########################################################
function
GetVserverQuotaInfoOutput { # args[0] = vservername
$vserverName
= $args[0]
$output
= GetVserverQuotaInfo $vserverName
$i
= 0
$stop
= $null
"Vserver
# Volume # Qtree # Volume Quota State # Disk Used (KB)"
do
{
$vserverOut
= $output[0,$i]
$volumeOut
= $output[1,$i]
$qtreeOut
= $output[2,$i]
$quotaStateOut
= $output[3,$i]
$diskUsedOut
= $output[4,$i]
if
($vserverOut){"$vserverOut # $volumeOut # $qtreeOut # $quotaStateOut #
$diskUsedOut"}
if
(!$vserverOut){$stop = "true"}
$i++
} while (!$stop)
}
# END of function GetVserverQuotaInfoOutput
###########
# THE END #
###########
Comments
Post a Comment