Effective December 3, NetApp adopts Microsoft’s Business-to-Customer (B2C) identity management to simplify and provide secure access to NetApp resources.
For accounts that did not pre-register (prior to Dec 3), access to your NetApp data may take up to 1 hour as your legacy NSS ID is synchronized to the new B2C identity.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Microsoft Virtualization Discussions

need to store volume size in a stored volume name read from powershell read-host

ARB

Hello All,

 

I am writing a powershell script, where I want the user to input all the source and destination info. 

 

I am collecting the source volume from read-host .

 

Once the source volume is choosen, I need to  store the choosen volume size in a variable so that destination volume can be created with the same size. 

 

Please check the code and suggest.

 

 SAMPLE CODE:

=============

# Script to check and initiate snapmirror process for 7M
Import-Module DataONTAP
write-host "Enter the FQDN/IP of the source controller"
$Source_Controller = read-host
$cred = Get-Credential "root"
write-host "Source Controller Name= $Source_Controller"
write-host "==========================================="
Connect-NaController $Source_Controller -Credential $cred

Write-Host "Snapmirror process will be started"
Get-NaVolSpace | ft Volume,VolumeSize,@{Name="VolSize(GB)";expression={$_.volumesize/1GB}} -AutoSize
Write-Host "Choose the source volume which needs to have DR"
$Source_Vol = Read-Host.name
Write-Host " $Source_Vol is choosen for which DR has to be configured"

write-host "Enter the FQDN/IP of the Destination/DR controller"
$DR_controller = read-host
write-host "DR Controller Name=$DR_controller"
write-host "=================================="
Connect-NaController $DR_controller -Credential $cred

Write-Host "choose the aggregate where you want the DR volume to be created"
Get-NaAggr | ft Name,State,TotalSize,Used,Available,@{Name="Totalsize(GB)";expression={$_.TotalSize/1GB}},@{Name="AvailableSize(GB)";expression={$_.Available/1GB}}
$DR_Aggr = Read-Host

Write-Host " Source controller: $source_controller,Source volume: $Source_Vol, DR Controller: $DR_controller,DR_Aggr: $DR_Aggr are choosen as the vol/Aggr for DR creation" -ForegroundColor DarkGreen


Write-Host " Creating DR volume in DR controller"

 

 

1 ACCEPTED SOLUTION

asulliva

The simplest is probably a regular expression...something like this:

 

"abc123ABC" -match "^[a-zA-Z0-9]*$"

Which will return true if the string is only lower case, upper case, or numbers...

 

$string = "abc123ABC"

if ($string -match "^[a-zA-Z0-9]*$") {
    Write-Output "This is a positive match"
} else {
    Write-Output "This is a negative match"
}

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

4 REPLIES 4

asulliva

Once you have the volume name, retrive it's properties using the "Get-NaVol" cmdlet...

 

Write-Host "Choose the source volume which needs to have DR"
$Source_Vol_Name = Read-Host

$Source_Vol = Get-NcVol -Name $Source_Vol_Name

The size of the volume would then be accessible using "$Source_Vol.SizeTotal".

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

ARB

 

 

 

asulliva

The simplest is probably a regular expression...something like this:

 

"abc123ABC" -match "^[a-zA-Z0-9]*$"

Which will return true if the string is only lower case, upper case, or numbers...

 

$string = "abc123ABC"

if ($string -match "^[a-zA-Z0-9]*$") {
    Write-Output "This is a positive match"
} else {
    Write-Output "This is a negative match"
}

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

ARB

Thanks for the details. got the idea to execute 

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