Continuing from the previous post ... a few
Get-NcCommands erred with “This cmdlet must be directed to a data vserver”. The
following (simpler) script handles those. My learned list of this
Get-NcCommands - that need to be directed to a data vserver - from running
against an ONTAP 8.3.2 SIM was:
Get-NcCifsHomeDirectorySearchPath,Get-NcCifsOption,Get-NcCifsSecurity,Get-NcFcpNodeName,Get-NcFileInodeInfo,Get-NcIscsiNodeName,Get-NcIscsiTargetAlias,Get-NcNameServiceUnixGroupFileOnly,Get-NcNameServiceUnixUserFileOnly,Get-NcNfsExport,Get-NcNfsSecurityFlavor,Get-NcSnapshotRestoreStatus,Get-NcVolCloneSplit,Get-NcVolFlexgroupAggrLayout,Get-NcVolLimit,Get-NcVolRoot
Image: Files and
Outputs with Collect-NcDataSVM.ps1
The Script
##
INPUTS: ##
Param(
[Parameter(Mandatory=$True)][String]$Cluster,
[Parameter(Mandatory=$True)][String]$UserName,
[Parameter(Mandatory=$True)][Security.SecureString]$Password,
# TIP: Use PS> $P = Read-Host
-AsSecureString
[String]$DirectToVserverFile =
"~DirectToVserver.CSV"
)
##
OUTPUTS: ##
#
$Cluster\~Timings.$Vserver.CSV - used for timing how long the Get-Ncs take
#
$Cluster\$Cluster.$Vserver.$GetNc.XML - for each Get-Nc
##
FUNCTION: Collect-NcData ##
Function
Collect-NcDataSVM{
Param(
[Parameter(Mandatory=$True)][String]$Cluster,
[String]$DirectToVserverFile =
"~DirectToVserver.CSV"
)
## TEST/LOAD ##
If(!(Test-Path $DirectToVserverFile)){
("ERROR: Unable to access path: $DirectToVserverFile"); RETURN }
[System.Array]$GetNcs = (Import-CSV
$DirectToVserverFile)."NAME"
[Void](New-Item "$Cluster"
-ItemType Directory -Force)
If(!(Test-Path $Cluster)){ ("ERROR:
Unable to access folder: $Cluster"); RETURN }
## COLLECT DATA ##
[System.Array]$DataSVMs = (Get-NcVserver |
Where{ $_.VserverType -eq "data" }).Vserver
[System.Array]$TimingsOutput =
"SVM,NAME,Time(Secs)"
Foreach($SVM in $DataSVMs){
$global:currentnccontroller.Vserver = $SVM
Foreach($GetNc in $GetNCs){
$Time1 = Get-Date -uformat %s
"INFO_: Collecting for $SVM :
$GetNc"
[System.Array]$NcData = Invoke-Expression
$GetNc
If($NcData){ $NcData | Export-CLIXML
"$Cluster\$Cluster.$SVM.$GetNc.XML" }
$TimingsOutput +=
"$SVM,$GetNc," + [math]::Round(((Get-Date -uformat %s) - $Time1),2)
}
}
"INFO_: Finished data collection"
$TimingsOutput | Out-File
"$Cluster\~Timings.$SVM.CSV" -Encoding Default -Force
}
##
GENERIC: Load PSTK ##
"INFO_:
Loading the Data ONTAP PSTK"
If(!(Get-Module
DataONTAP)){ [Void](Import-Module DataONTAP -ErrorAction SilentlyContinue) }
If(!(Get-Module
DataONTAP)){ "ERROR: Failed to load Data ONTAP PSTK"; EXIT }
##
GENERIC: Connect to Cluster ##
"INFO_:
Connecting to $Cluster"
$Cred
= New-Object System.Management.Automation.PsCredential($UserName,$Password)
If(!(Test-Connection
$Cluster)){ "ERROR: Cannot ping to $Cluster"; EXIT }
$Global:CurrentNcController
= $NULL
[Void](Connect-NcController
-Name $Cluster -Credential $Cred)
If(!$Global:CurrentNcController){
"ERROR: Cannot connect to $Cluster"; EXIT }
##
MAIN PROGRAM ##
Collect-NcDataSVM
$Cluster
Comments
Post a Comment