NetApp PowerShell Toolkit – Templates

There’s one particular part of the NetApp PowerShell Toolkit which is not frequently used, but is extremely powerful. Templates can be created for many of the object types which are used to create a query for specific objects, or for limiting the amount of information returned from a particular cmdlet invocation.

To get started, we first need to initialize the object for our query or attribute limiting template. To do this we use the -Template parameter to our cmdlet.

If we were to look at this object it is empty:


Many of the properties associated with an object, such as an aggregate, volume, or LUN, are objects themselves. If we want to use a property of a child object as the query filter then we need to initialize that property in the template object.

Our template object now has a property object which has been populated:


At this point we’re ready to use the template, let’s look at how to use it as a query or to limit the attributes returned.

Query / Filter Templates

Using query templates means that filtering happens on the NetApp, not the client side. If you execute Get-NcVol against your cluster which has thousands of volumes it may take a bit for that to execute, and when it does your client will have to work hard to process the result and turn it into objects. This is even more important when you’re looking for volumes with specific properties…instead of all volumes being returned and then piping to Where-Object to select a handful.

At this point the returned objects would be exactly as expected, they contain all properties of a standard Get-* cmdlet invocation.

Queries without the template

There is also a way to shortcut doing a query using hash tables. This makes it super easy to do queries on the NetApp side and eliminate work from the client.

Query with wildcards and relative numbers

The extremely simple examples above use static values for the queried properties, but we can use wildcards and other operators on the values as well.

The list of query operators we can use here is the same as at the CLI. I haven’t show them here, but OR (|), less than or equal to (<=), and greater than or equal to (>=) are all available as well.

Attribute Limiting Templates

For many of the objects returned by the Toolkit there is a huge amount of information available. This is useful when we don’t know what information we’re looking for, or if we want to explore around and see what information is in the result. But, if we are executing a script which doesn’t need all that extra info it can greatly speed up execution by reducing the information returned…not to mention remove that extra work from the system on the other end.


Returning only the name is helpful if we only need that information, for example if we’re piping into a Foreach-Object loop and querying for volumes per aggregate. Notice that with this empty template none of the other properties in the output are populated.

If we want additional properties we use the same Initialize-NcObjectProperty cmdlet to specify the properties.


Templates are awesome!

Templates are a powerful feature which can help you to significantly speed up the execution of your scripts. For proof, here are two examples where filtering on the storage side reduces the execution time by 75%, and returning only the properties needed reduces execution time by almost 85%!



Leave a Reply