Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
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"
Solved! See The Solution
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
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
Hello asulliva,
Thanks for the details, have checked and it is working fine.
I got another small query,
I need to have checks to make sure if the inputs provided in the program is not as desired it should exit. Can you suggest a best way of doing it
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
Thanks for the details. got the idea to execute