Microsoft Virtualization Discussions

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

ARB
3,720 Views

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
3,557 Views

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
3,667 Views

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
3,625 Views

 

 

 

asulliva
3,558 Views

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.

ARB
3,536 Views

Thanks for the details. got the idea to execute 

Public