Microsoft Virtualization Discussions

toolkit output questions

wnorthmtitsd
4,247 Views

First, I am very new to PowerShell and the toolkit.

When I use some commandlets in a shell I get blank lines for output.

such as when I put in Get-NaSystemOntapiVersion

Tried piping it to foreach and then assigning the variable I wanted, in this case MajorVersion and MinorVersion but I still get nothing

Obviously I am missing something.

Can someone explain in plain language (as opposed to powershell speak) what that might be ?

thanks!

1 ACCEPTED SOLUTION

timothyn
4,247 Views

Ahh, so the commands inside the loop don't output text, they return objects directly on the pipeline.  You essentially end up with a list of controller, ontapi version, controller, ontapi version, and so on.   Because you have a select statement in there and multiple types in the output, PowerShell is getting confused and doesn't know how to format the objects.

Instead, one option is to use the Select-Object cmdlet to combine the controller and Ontapi Version into a single object:

$hostnames = @("10.61.169.28", "10.61.165.227")

foreach ($hostname in $hostnames)

{

   $cntlr = Connect-NaController $hostname

    Get-NaSystemOntapiVersion |

        select @{Name="Name";Expression={$cntlr.Name}},

               @{Name="Address";Expression={$cntlr.Address}},

               MajorVersion, MinorVersion

}

which outputs this:

Name                         Address                                        MajorVersion                MinorVersion
----                         -------                                        ------------                ------------
10.61.169.28                 10.61.169.28                                              1                          13
10.61.165.227                10.61.165.227                                             1                           7

Of course this example is a bit contrived since the controller object already includes an OntapiVersion property, but it would apply similarly to any other information you gather per controller...

Hope that helps!

View solution in original post

5 REPLIES 5

wnorthmtitsd
4,247 Views

I figured out the foreach part, but not why it would not list things without using the foreach

timothyn
4,248 Views

Could you post an example from importing the module to the Get-NaSystemOntapi cmdlet?  Something like this:

PS C:\> ipmo dataontap

PS C:\> Connect-NaController 10.61.169.28

Name                 Address           Ontapi   Version

----                 -------           ------   -------

10.61.169.28         10.61.169.28      1.13     NetApp Release 8.0.1 7-Mode: Wed Jan  5 17:24:41 PST 2011

PS C:\> Get-NaSystemOntapiVersion

                           MajorVersion                            MinorVersion NodeOntapiDetails

                           ------------                            ------------ -----------------

                                      1                                      13 {fas2040rre1}

Thanks!

wnorthmtitsd
4,248 Views

Hi Eric,

Here is the relevant part of the ps script

Import-module DataOnTap

$NetappList=("Controller-1","Controller-2")

$cred = "appropriate definition of $cred here"

foreach ($netapp in $NetappList) {   

   Connect-nacontroller -credential $cred $netapp | select Name,Address

    Get-NaSystemOntapiVersion

}  # End netapplist foreach

When I run these commands from the command line the output is what you show

thanks!

timothyn
4,248 Views

Ahh, so the commands inside the loop don't output text, they return objects directly on the pipeline.  You essentially end up with a list of controller, ontapi version, controller, ontapi version, and so on.   Because you have a select statement in there and multiple types in the output, PowerShell is getting confused and doesn't know how to format the objects.

Instead, one option is to use the Select-Object cmdlet to combine the controller and Ontapi Version into a single object:

$hostnames = @("10.61.169.28", "10.61.165.227")

foreach ($hostname in $hostnames)

{

   $cntlr = Connect-NaController $hostname

    Get-NaSystemOntapiVersion |

        select @{Name="Name";Expression={$cntlr.Name}},

               @{Name="Address";Expression={$cntlr.Address}},

               MajorVersion, MinorVersion

}

which outputs this:

Name                         Address                                        MajorVersion                MinorVersion
----                         -------                                        ------------                ------------
10.61.169.28                 10.61.169.28                                              1                          13
10.61.165.227                10.61.165.227                                             1                           7

Of course this example is a bit contrived since the controller object already includes an OntapiVersion property, but it would apply similarly to any other information you gather per controller...

Hope that helps!

wnorthmtitsd
4,248 Views

Ahhhh, I would have thought the select in the connect-nacontroller statement would have only acted on that statement, but after reading your response I see that it apparently does not.  Removing it from the connect statement returns the output I would have thought I would see.

I have a long way to go to understand the PowerShell stuff!

thanks!

Public