Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
Hi guys,
I started playing with powershell this week - I've tried to run the following but getting this:
"the size of the volume is DataONTAP.Types.Volume.SizeInfo"
the script is:
Import-Module dataontap
$filername = Read-Host 'What is the filer hostname?'
$name = Read-Host 'What is your username?'
Connect-NaController -Name $filername -Credential $name
$volname = Read-Host 'What is the volume name?'
$volsize = Get-NaVolSize -Name $volname
Write-Host "the size of the volume is:" $volsize
my debugger is saying that my problem is in this line:
$volsize = Get-NaVolSize -Name $volname
Thank you
Solved! See The Solution
I am late to the discussion, but this is working for me:
Import-Module dataontap
$filername = Read-Host 'What is the filer hostname?'
$name = Read-Host 'What is your username?'
Connect-NaController -Name $filername -Credential $name
$volname = Read-Host 'What is the volume name?'
$volsize = Get-NaVolSize -Name $volname
Write-Host "the size of the volume is:" ($volsize).volumesize
What is the error that the debugger is throwing out?
-Scott
Make sure you set your execution policy to unrestricted.
Is your storage controller joined to the domain? If so, then is your domain account (logged on with) a member of the storage controllers administrator's group?
If yes, then:
Import-Module dataontap
$filername = Read-Host "What is the filer hostname?"
Connect-NaController -Name $filername | out-null
$volname = Read-Host "What is the volume name (case sensitive)?"
$volsize = Get-NaVolSize $volname
Write-Host "The size of the volume is:"$volsize.volumesize
If no, then:
Import-Module dataontap
$filername = Read-Host "What is the filer hostname?"
Connect-NaController -Name $filername -Credential (get-credential) | out-null
$volname = Read-Host "What is the volume name (case sensitive)?"
$volsize = Get-NaVolSize $volname
Write-Host "The size of the volume is:"$volsize.volumesize
no go
Thanks though
I am late to the discussion, but this is working for me:
Import-Module dataontap
$filername = Read-Host 'What is the filer hostname?'
$name = Read-Host 'What is your username?'
Connect-NaController -Name $filername -Credential $name
$volname = Read-Host 'What is the volume name?'
$volsize = Get-NaVolSize -Name $volname
Write-Host "the size of the volume is:" ($volsize).volumesize
What is the error that the debugger is throwing out?
-Scott
Scott,
I am getting this:
"the size of the volume is DataONTAP.Types.Volume.SizeInfo"
The only difference between my script and yours is this:
mine:
Write-Host "the size of the volume is:" $volsize
yours:
Write-Host "the size of the volume is:" ($volsize).volumesize
(is that my issue?)
I would have to try that again with your line
I'll let you know
Thanks
Yep, you need to call the property(volumesize) of the object ($volsize). Otherwise it simply returns the object type, not the usable information of the object.
-Scott
sweet
I'll try that and let you know
Thanks
Joel
I have to wonder--is there any reason NetApp implements the ToString method on this object to output the object type name as a string instead of the volumesize integer itself?
I cannot say on authority, but powershell is object oriented, therefore in this context the request is for an object that is being called back into a variable. Now $volsize is an object, to get that object's information, you have to reference the property . The property of variable/object $volsize is the output, and in order to conform to proper syntax and compatibility it should be required to call (object).property. Otherwise you end up with no idea of how one output should be called in reference to another. By that what I mean is what object only has one property and therefore will output a single property as int/str/arr, etc? You could not expect to write anything with any certainty because the rule could change for every single output, now multiply that by every vendor doing it their own way, gets to be a mess very quickly.
If you run get-navolsize -name vol0, you get a default output which is a header, separator, and the output integer.
-Scot
Works!
Thanks Scott
Can we take it a step further?
- How do I list all volumes (just volume names) and Read-Host "pick a volume from the list to show its size"
- If the input volume name does not exist, can we display a message >> "volume doe not exist, try again"
Cheers
Joel, I am in training, but I have attached a script here that does the same sort of thing for finding CIFS shares and setting the browse/nobrowse option. I have added some notes to it, but I should be able to work with it to do this for volumes sometime next week(should be pretty simple).
Also for the write-output, that comes out in bytes, an easy format option is to use write-output ($volsize).volumesize |convertto-formattednumber -type datasize
-Scott
Message was edited by: Scott Chubb for spelling/grammar
Scott, what does this line do? >> $volList = @($volList)
Dynamically builds an array so that we can build a menu for any number of volumes. '@' indicates an array, so for each volume found by get-navol, we put them into an array, then use that to build the menu and further on to identify which object we want to see the output on.
FYI, for clarity - Powershell 2.0 has some issues building single item arrays. I have to use $volist = @($volist) for the times that I end up with only a single entry in the array. Powershell 2.0 will reset it to a string unless you explicitly call it again as an array, Powershell 3.0 is supposed to fix this, but I am not ready to move to 3.0 yet.
-Scott
Message was edited by: Scott Chubb for clarity and additional information.
Scott, the script worked with the first filer (netapp03 - # 2) I picked but when I run it again against another filer ( # 0 or 1) it gives me this:
I know for sure that netapp01 and netapp02 exist and they use the same credentials
Here is the script
===========================================
Import-Module dataontap
#You will need to change PASSWORD to use the login credentials. This required httpd.admin.enable to be set to on
#You will need to change myNode for each filer you want to add. You may need to add/remove nodes for your environment
#
#Ensure the user enters a number
Function isNumeric ($x) {
$x2 = 0
$isNum = [System.Int32]::TryParse($x,[ref]$x2)
return $isnum
}
#Build the list of shares by system and set the option to hide/show the share
Function listFilerShares {
#secure login creations
$myNetAppUser = "root"
$myNetAppArrayPass = "<change_with_your_password>"
$myNetAppPass = ConvertTo-SecureString $myNetAppArrayPass -AsPlainText -Force
$myNetappCred = New-Object -TypeName system.Management.Automation.PSCredential -ArgumentList $myNetAppUser,$myNetAppPass
connect-nacontroller $mySelectedNode -Credential $myNetAppCred
#get a list of shares and build an array
$volList = Get-NaVol |ForEach-Object {write-output $_.Name}
$volList = @($volList)
$i = 0
while ($i -le ($volList.length - 1 ))
{
Write-Host "$i.) "$volList[$i]
$i++
}
[int]$volMenu = Read-Host "select a volume by number"
while (-not(isNumeric $volMenu))
{
[int]$volMenu = Read-Host "Error in entry : select a volume by number"
}
while (-not($volMenu -le ($volList.length - 1 )))
{
$volMenu = Read-Host "Error in entry : select a volume by number"
}
$volSize = get-navolsize -Name $volList[$volMenu]
Write-Output ($volSize).volumesize | ConvertTo-FormattedNumber -Type datasize
}
#Build a menu of filers to select from
Write-Host "Select a filer by number"
write-host "0.) netapp01"
write-host "1.) netapp02"
write-host "2.) netapp03"
Write-Host " "
$mySelectedNode = Read-Host "Select 0-2"
while (-not(isNumeric $mySelectedNode))
{
$mySelectedNode = Read-Host "Select 0-2"
}
while (-not($mySelectedNode -le 2))
{
$mySelectedNode = Read-Host "Select 0-2"
}
switch ($mySelectedNode)
{
0 {
$mySelectedNode = "netapp01"
}
1 {
$mySelectedNode = "netapp02"
}
2 {
$mySelectedNode = "netapp03"
}
}
listFilerShares
=====================================
Thanks
Joel
2 more questions:
1. How do I list failed disks?
2. How do I show Snapmirror Lag of (only) more than 24 hours?
I've tried this:
(Get-NaSnapmirror).LagTimeTS | {$_.Hours -gt 24}
Cheers
I already have a script for checking my snapmirror lags, I have attached it here. (It appears that this is an older version that was not complete, I will post the finished version when I get back home on Monday.) The formatting section is something I have found on the communities, so I cannot take credit for the output being formatted so well.
As to the disks, I don't have anything that checks for it, but I am assuming that it will be something along the lines of:
get-nadisk | foreach-object | write-output $_.Name {where-object $_.Status -eq "failed" }.
"$_" means take whatever comes out of the foreach-object and use it as an object, in this case each disk is made a variable as it is found by the for loop.
Training is over around Noon eastern and I can use the simulator on my laptop to see how badly I have mangled that disk command.
-Scott
Message was edited by: Scott Chubb - removed script, which was not the correct version.
Joel,
Sorry got busy and forgot about this. I did some minor editing as there was a problem with the formatting. This is the touchiest script I have....the formatting has to have everything just so, and I have never set down long enough to learn what the difference is in how this formatting is invoked.
-Scott
So for this let's do something basic:
replace this:
$myNetAppUser,$myNetAppPass
connect-nacontroller $mySelectedNode -Credential $myNetAppCred
with this:
$myNetAppUser,$myNetAppPass
write-output $mySelectedNode
connect-nacontroller -Name $mySelectedNode -Credential $myNetAppCred
This will allow us to make sure that we are getting the node name from the switch statement properly. If we see the node we expect to see, we have an issue outside the script in most cases.
-Scott
Thanks Scott - I'll try that and let you know