It seems
funny to be still writing PowerShell tools for Data ONTAP 7-Mode, but this one
is actually very useful. You point it at your 7-Mode Controller, and it will
collect all the config files and CLI outputs - for vFiler0 and any and all
vFilers – and store the outputs in a folder per vFiler. A couple of examples of
using it are below:
Example 1: Running as .\Collect7.ps1
Example 2: Running as .\Collect7.ps1 -System7M
fas02 -UserName root -Password $PW
The Script
Copy into a text editor and save as Collect7.ps1. I’ve kept the script
fairly compact. Edit the sections -
CONFIG
FILES TO COLLECT
CLI
OUTPUTS TO COLLECT
- as per
requirements.
#########################################################
## COLLECT7: 7-MODE VFILER0
AND VFILERS DATA COLLECTOR ##
#########################################################
Param(
[Parameter(Mandatory=$True)][String]$System7M,
[Parameter(Mandatory=$True)][String]$UserName,
[Parameter(Mandatory=$True)][SecureString]$Password
) # Tip: You can use> $PW
= Read-Host -AsSecureString, as input for -Password
FUNCTION Wr{
Param([String]$P="",[String]$C="WHITE"); Write-Host $P
-ForegroundColor $C}; Wr
FUNCTION Get-7mConfigFile{
Wr "Reading the file: $CFGFILE"
CYAN
[String]$StrOut = Read-NaFile ($ETCPATH +
"/" + $CFGFILE)
If(!$StrOut){ RETURN }
[System.Array]($StrOut.Split("`n"))
| Set-Content ($SaveDir + "/" + $CFGFILE)
}
FUNCTION Get-7mCliOutput{
Wr "Getting the output of> $COMMAND
" CYAN
If($vFiler -eq "vFiler0"){
[String]$StrOut = Invoke-NaSsh -Command $COMMAND }
else{ [String]$StrOut = Invoke-NaSsh -Command
"vfiler run $vFiler $COMMAND" }
If(!$StrOut){ RETURN }
[System.Array]($StrOut.Split("`n"))
| Set-Content ($SaveDir + "/CLI_OUT_" + $COMMAND)
}
FUNCTION Collect7{
[String]$SaveDir = ($System7M + "."
+ $vFiler)
[Void](New-Item -Path $SaveDir -ItemType
Directory -Force)
$global:CurrentNaController.vfiler = $vFiler
If($vFiler -eq "vFiler0"){
$global:CurrentNaController.vfiler = "" }
$RootVol = (Get-NaVolRoot -ErrorAction
SilentlyContinue).Name
If ($RootVol){ $ETCPATH = "/vol/" +
$RootVol + "/etc" }
else{ $ETCPATH = (Get-NaCifsShare -Share
ETC$).MountPoint }
If (!$ETCPATH){ Wr "Unable to get /etc
path for $vFiler!" RED; RETURN }
Wr "ETC path for vFiler: $vFiler is
$ETCPATH " GREEN
Foreach($CFGFILE in $CfgFiles){
[Void](Get-7mConfigFile) }
Foreach($COMMAND in $Commands){
[Void](Get-7mCliOutput) };Wr
}
<# CONFIG FILES TO
COLLECT: #>; [System.Array]$CfgFiles = `
"cifs_homedir.cfg",`
"cifs_nbalias.cfg",`
"cifsconfig_share.cfg",`
"exports",`
"hosts",`
"hosts.equiv",`
"netgroup",`
"nsswitch.conf",`
"quotas",`
"rc",`
"resolv.conf",`
"snapmirror.allow",`
"snapmirror.conf",`
"symlink.translations",`
"usermap.cfg",`
"dgateways",`
"lclgroups.cfg"
<# CLI OUTPUTS TO
COLLECT: #>; [System.Array]$Commands = `
"cifs shares",`
"cifs
domaininfo",`
"snapvault
status",`
"snapmirror
status",`
"nis info",`
"fpolicy",`
"vscan",`
"rlm status",`
"sp status",`
"bmc status",`
"options",`
"sysconfig -v",`
"quota status",`
"exportfs"
## MAIN PROGRAM ##
If(!(Get-Module DataONTAP)){
[Void](Import-Module DataONTAP -ErrorAction SilentlyContinue) }
If(!(Get-Module DataONTAP)){
Wr "Failed to load DataONTAP PSTK!" RED; EXIT }
Wr "Loaded DataONTAP
PSTK" GREEN; Wr
Wr
"<<<<< COLLECT7: 7-MODE VFILER0 AND VFILERS DATA COLLECTOR
>>>>>" MAGENTA; Wr
$Cred = New-Object
System.Management.Automation.PsCredential($UserName,$Password)
[Void](Connect-NaController
$System7M -Credential $Cred -ErrorAction SilentlyContinue)
If(!$Global:CurrentNaController){
Wr "Failed to connnect to $System7M!" RED; EXIT }
Wr "Connected to
$System7M" GREEN
[System.Array]$vFilers =
"vFiler0"
If(Get-NaVFiler -ErrorAction
SilentlyContinue){ [System.Array]$vFilers = (Get-NaVFiler).Name }
Foreach($vFiler in
$vFilers){ [Void](Collect7) }
Comments
Post a Comment