Hi All, I need to update a PowerShell script that uses get-ncvol. I see a remark in the man (get-help) page for the function that I could do an advanced query, it seems to indicate that I first setup a template via "-Template -Fill" then I defines some attributes that are of interest i.e. to filter the results. But how do I specify the attributes e.g. how do ask for something like: all volnames matching "acme" and/or only "data" SVMs?
#Get-NcVol and advanced queries / Templates
1 messages · Page 1 of 1 (latest)
So in this case volnames such as acme_002, test_acme, ...
Overall is this a good approach? It seems like using the templates in the query instead of filtering the results afterwards (in PowerShell) should be more efficient, place less load on the Filers ...
I have used templates with Update-NcFoo style commands since there it is mandatory. For simple queries I found it easier to just grab all items and filter in PowerShell, like
Get-NcVol | ? { $_.State -ne "offline" } |
{ ! $_.VolumeStateAttributes.IsConstituent } |
Set-NcVol -Offline -Confirm:$false
If you want to use templates with Update-NcFoo commands, you can do it like this:
$q = Get-NcVol -Template
Initialize-NcObjectProperty $q VolumeIdAttributes
$q.VolumeIdAttributes.OwningVserverName = "!Node*"
$a = Get-NcVol -Template
Initialize-NcObjectProperty $a VolumeSnapshotAttributes
$a.VolumeSnapshotAttributes.SnapshotPolicy ="none"
Update-NcVol -Query $q -Attributes $a
this sets the Snapshot Policy for all volumes that are not node-owned (i.e. not the system root volumes) to "none"
yeah. I think it should accept all wildcards that the CLI accepts, so for numers >10g or similar should also work, but I haven't tried that yet
( need to put Discord into raw mode 😉 )
I will give it a try and let you know the results!
good luck. And again, you can always use PowerShell's -match operator if you just iterate over all items/volumes/vservers
Get-NcVol | ? { $_.Name -match "*acme*" }
PowerShell is usually more versatile with what you can do/match/filter against
TBH, I am more of a UNIX/Linux/Perl kinda guy 😎
( or maybe golang )
you can do that there too, there's Python and Perl bindings IIRC, and I guess you can also filter there more easily than with what ONTAP provides
Also, there's PowerShell for Linux too 🙂
Just tooling around, hacking some other guys PS script ... on the typical Windows jumpserver, where I have no admin rights ... Another day in paradise 🙄
You wrote: " ... OwningVserverName = "!Node*" ..."
Where is "Node" coming from there?
Your own local var, or built into the netapp lib/toolkit?
the name of our nodes. "Node01", "Node02", etc.
(it was just a direct copy/paste from one of our cleanup scripts... we're not very creative with naming our lab systems 😄 )