Microsoft Virtualization Discussions

loop

JSHACHER11
6,440 Views

Following up on my last post, I have this script that I need to loop

++++++++++++++++++++++++++++++++++++++

Import-Module Dataontap

write-host ""

write-host ""

write-host "This script will list volumes over 80% full, the containing aggregates and snapmirror relationships" -foregroundcolor yellow

write-host ""

write-host ""

write-host "You will also get an option to increase a volume size" -foregroundcolor yellow

write-host ""

write-host ""

$filer = Read-Host "Enter the filer name"

$user = Read-Host "Enter username"

Connect-NaController -Name $filer -Credential $user

get-navol | ? {$_.used -gt 80} | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}} | ft -Autosize | Out-String

write-host ""

write-host ""

write-host "Here are the aggregates:" -foregroundcolor yellow

write-host ""

write-host ""

get-naaggr | select name,@{Name="Total Size (in GB)";Expression={[math]::truncate($_.totalsize/1gb)}},used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.available/1gb)}} | ft -Autosize | Out-String

write-host ""

write-host ""

write-host "and the snapmirror relationships:" -foregroundcolor yellow

write-host ""

write-host ""

get-navol | ? {$_.used -gt 80} | get-nasnapmirror | select source,destination | ft -Autosize | Out-String

write-host ""

write-host ""

$ans = Read-Host -prompt "Would you like to increase one of the volumes? [Y/N]"

write-host ""

write-host ""

if ($ans -eq "N") {

exit

} else {

$vol = Read-Host "Enter volume name"

$size = Read-Host "How much more space do you want to give it? (example: +100g)"

Set-NaVolsize -Name $vol -NewSize $size -Confirm

Write-Host ""

Write-Host ""

Write-Host "Check the new size:" -foregroundcolor yellow

Write-Host ""

Write-Host ""

Get-NaVol -Name $vol | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}}

}

+++++++++++++++++++++++++++++++++++++++++++

The above gives me the option to increase a volume size but will only run once. I'm after a loop that will give me an option to choose to run the Set-NaVolsize again.

It should be something like this at the end of the script:

$ans = Read-Host -prompt "Would you like to increase another volumes? [Y/N]"

if ($ans -eq "N") {

exit

} else {

$vol = Read-Host "Enter volume name"

$size = Read-Host "How much more space do you want to give it? (example: +100g)"

Set-NaVolsize -Name $vol -NewSize $size -Confirm

Write-Host ""

Write-Host ""

Write-Host "Check the new size:" -foregroundcolor yellow

Write-Host ""

Write-Host ""

Get-NaVol -Name $vol | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}}

}

so the above should loop until the input is N (no) - how do I do that?

Thank you

1 ACCEPTED SOLUTION

JGPSHNTAP
6,438 Views

Ok, so let me address a few issues here

First, you shouldn't be importing the module every time you run the script.  You should add it to your profile.  And someone mentioned to me that the module will load automatically in 3.0, but i haven't tested that.  Look up Powershell profiles. 

First, you should eliminate all the Write-host ""

You should use something like

Write-Host "`n`nCheck the new size:`n`n" -foregroundcolor yellow

Also, as stated in previous email, you should be using the convertto-formattednumber cmdlet in place of - Expression={[math]::truncate($_.Available/1gb)}},    It's a custom Dataontap module cmdlet that will help with other future scripts

As for your loop. you need to focus on something like Do.... Until.

something like

Do {

$ans = Read-Host -prompt "Would you like to increase one of the volumes? [Y/N]"

write-host ""

write-host ""

if ($ans -eq "N") {

exit

} else {

$vol = Read-Host "Enter volume name"

$size = Read-Host "How much more space do you want to give it? (example: +100g)"

Set-NaVolsize -Name $vol -NewSize $size -Confirm

Write-Host ""

Write-Host ""

Write-Host "Check the new size:" -foregroundcolor yellow

Write-Host ""

Write-Host ""

Get-NaVol -Name $vol | select name,used,@{Name="Available Size (in GB)";Expression={[math]::truncate($_.Available/1gb)}},@{Name="Total Size (in GB)";Expression={[math]::truncate($_.sizetotal/1gb)}}

}

}

Until ( $ans -eq "N")

Enjoy!

View solution in original post

10 REPLIES 10
Public