Subscribe

Netapp powershell toolkit

Hi,

 

Is there a netapp powershell toolkit script to get the uptime of the filer?

 

Thanks in advance!

 

Regards,

Mark Gemina

Highlighted

Re: Netapp powershell toolkit

Hi Mark,

 

The uptime is based on the cluster node (assuming you are referring to cDOT). I don't think there is any CmdLet for this but you can run the SSH command and parse the output.

Here is an example:

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The hostname or IP Address of the cluster")]
   [String]$Cluster
)
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Import-Module DataONTAP -ErrorAction SilentlyContinue
$credentials = Get-Credential -Credential "admin"
Try{
   Connect-NcController -Name $Cluster -HTTPS -Credential $credentials -ErrorAction Stop | Out-Null
   Write-Host "Connected to cluster ""$Cluster"""
}Catch{
   Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Enumerate the uptime.
#'------------------------------------------------------------------------------
[String]$command = "system node show -fields uptime -node *"
Try{
   $output = Invoke-NcSsh -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Display the SSH output.
#'------------------------------------------------------------------------------
Write-Host $output.Value
#'------------------------------------------------------------------------------
#'Add the SSH output into a hashtable.
#'------------------------------------------------------------------------------
[HashTable]$nodeUptime = @{};
[Array]$results        = $output.Value.Split("`r`n")
For($i = 3; $i -le $results.Count; $i++){
   If($results[$i] -ne "" -And $results[$i] -ne $Null){
      [Array]$elements = $results[$i].Split(" ")
      [String]$node    = $elements[0].ToString().Trim();
      [String]$uptime  = $($results[$i] -Replace($node, "")).ToString().Trim();
      If(-Not($nodeUptime.ContainsKey($node))){
         If(-Not($uptime -Match "entries were displayed")){
            $nodeUptime.Add($node, $uptime)
         }
      }
   }
}
$nodeUptime
#'------------------------------------------------------------------------------

Example output:

 

PS C:\Scripts\PowerShell\Projects\GetClusterUptime> .\GetClusterUptime.ps1 -Cluster hecklers
Connected to cluster "hecklers"
Executed Command: system node show -fields uptime -node *
node        uptime
----------- ------------
hecklers-01 9 days 08:09
hecklers-02 9 days 08:09
waldorf-01  9 days 08:09
waldorf-02  9 days 08:08
4 entries were displayed.

Name                           Value
----                           -----
hecklers-02                    9 days 08:09
waldorf-01                     9 days 08:09
hecklers-01                    9 days 08:09
waldorf-02                     9 days 08:08

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Netapp powershell toolkit

The uptime is returned as a property using the Get-NcNode cmdlet.

 

Get-NcNode | Select Node,NodeUptimeTS

 

Note that the NodeUptimeTS object is a TimeSpan type, this means it has a fair amount of detail.  Here's what one of my nodes looks like:

 

PS C:\Users\asull> Get-NcNode | Select Node,NodeUptimeTS

Node    NodeUptimeTS
----    ------------
VICE-07 31.06:30:06 
VICE-08 31.06:50:33 

PS C:\Users\asull> (Get-NcNode VICE-07).NodeUptimeTS | Out-String


Days              : 31
Hours             : 6
Minutes           : 31
Seconds           : 31
Milliseconds      : 0
Ticks             : 27018910000000
TotalDays         : 31.2718865740741
TotalHours        : 750.525277777778
TotalMinutes      : 45031.5166666667
TotalSeconds      : 2701891
TotalMilliseconds : 2701891000

Notice that the short format is "days.hours:minutes:seconds", or you can get each of those properties from the object individually.  For examle, you could do a much more friendly output for a report doing something like this:

 

“Node Uptime: {0:dd} days, {0:hh} hours, {0:mm} minutes” -f (Get-NcNode VICE-07).NodeUptimeTS

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Netapp powershell toolkit

I believe that Nc commands are for cmode. We are using 7-mode. Is there a command for 7-mode?

Re: Netapp powershell toolkit

[ Edited ]

Hi,

 

Sorry i just assumed you'd want the uptime for a cDOT system. Yes you are right, the *-Nc* CmdLets are for cDOT and the *-Na* CmdLets are for 7-Mode.

There is no PowerShell CmdLet for the uptime in 7-Mode but you can invoke the "uptime" command via SSH which is displayed as a string. EG:

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The hostname or IP Address of the controller")]
   [String]$Controller
)
#'------------------------------------------------------------------------------
#'Connect to the controller
#'------------------------------------------------------------------------------
Import-Module DataONTAP -ErrorAction SilentlyContinue
$credentials = Get-Credential -Credential "root"
Try{
   Connect-NaController -Name $Controller -HTTPS -Credential $credentials -ErrorAction Stop | Out-Null
   Write-Host "Connected to controller ""$Controller"""
}Catch{
   Write-Warning -Message $("Failed connecting to controller ""$Controller"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Enumerate the controller uptime.
#'------------------------------------------------------------------------------
[String]$command = "uptime"
Try{
   $output = Invoke-NaSsh -Command $command -ErrorAction Stop
   Write-Host "Executed Command`: $command"
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Break;
}
$output.Split(",")[0].Trim();
#'------------------------------------------------------------------------------

 

I tested it using a simulator, Example output:

 

PS C:\Scripts\PowerShell\Projects\GetControllerUptime> .\GetControllerUptime.ps1 -Controller testns01
Connected to controller "testns01"
Executed Command: uptime
6:21pm up 11 mins

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.