Microsoft Virtualization Discussions

first script

JSHACHER11

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

1 ACCEPTED SOLUTION

cscott

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

View solution in original post

32 REPLIES 32

JGPSHNTAP

Here, give this a shot

get-navol vol0 | get-navolsize | select @{E={convertto-formattednumber $_.volumesize datasize "0.00"};N="Vol size"}

JSHACHER11

sweet!

came out nice

so what does the 'E=' and 'N=' do?

JGPSHNTAP

Do a man on Select-object, It will show you.  It's Expression and Name

Actually, you can also do this.

[ValidateRange(1024,1125899906842624)]

[Int64]$Unit=1GB

$v = get-navol vol0 | get-navolsize

$v.volumesize/$unit

JSHACHER11

so is it similar to this:

C:\PS>get-process | select-object -property ProcessName,@{Name="Start Day"; Expression = {$_.StartTime.DayOfWeek}}

E --> Expression

N --> Name

?

JSHACHER11

JGPSHNTAP

Joel -

Do a quick search for a blog post i submitted that will dump out all the filers and volumes sizes etc... You can re-use the code for your liking.

I see from your flurry of posts that you are just getting going on PS which is great.  Start with the getting started powerpoint presentation as well.

Also, i'm noticing you are starting everything with import-module.  I believe in powershell 3.0 all modules are loaded. you can check that by launching powershell and typing get-module

If you are using 2.x you need to add import-module dataontap to your profile.ps1 file. 

vinith

Hello,

In the below scriptlet you are connecting to the controller only with username, you are not entering the password

$name = Read-Host 'What is your username?'

Connect-NaController -Name $filername -Credential $name

Try with the below method

$name = Read-Host 'What is your username?'

$password = Read-Host 'What is your Password?'

$ControllerPassword = ConvertTo-SecureString -String $password -AsPlainText -force

$credential = New-Object System.Management.Automation.PsCredential($name,$ControllerPassword)

Connect-NaController -Name $filername -Credential $credential

JSHACHER11

this line (Connect-NaController -Name $filername -Credential $name) brings up a popup that asks for a password. I insert the password and the script moves on

Again, my debugger is pointing to this line:

$volsize = Get-NaVolSize -Name $volname

Thank you

vinith

what are you giving as input to $volume, can you share an example?

Here's the output when i ran your set of cmdlets.

JSHACHER11

I've tried with a volume I created, called vol7 and also with vol0

spence

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

JSHACHER11

no go

Thanks though

cscott

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

View solution in original post

JSHACHER11

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

JSHACHER11

Vinith, that looks awesome! I'll try that later

Thanks

cscott

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

JSHACHER11

cscott

Here ya go! Since the user selects by number, there shouldn't be mistakes in vol name.  The script retains the check to make sure the user is entering a number, but now returns a human readable formatted vol size. (Got bored at lunch)

-Scott

JSHACHER11

Scott, what does this line do?  >>   $volList = @($volList)

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public