
UNSOLVED
DB
DELL-Bill Gr
50 Posts
0
12339
November 21st, 2011 12:00
Powershell - Map a Volume to Multiple Servers?
This post has been copied from the former Compellent User Forum and placed here for your reference. This code is made available AS IS, without warranty of any kind. The entire risk of the use or the results from the use of this code remains with the user.
Map a Volume to Multiple Servers? – Originally posted By CyberMartyr, 05 Jan 2010
CyberMartyr - Hi, We have a serveral VMWare servers accessing the same LUNs and I'd like to do the following.
Map Volumes to all 8 servers at once with the same LUN id and controller.
CMonfet - You can use this script, i use this all the time. My script assumes you already made a connection to the Compellent System, I leave the connection out of my script so no one takes them and accidentally runs them....Hope this helps you out.
#Generic Mapping Script
#written by Chris Monfet 11/07/09
#defining variables
$servername1= " "
$servername2= " "
$servername3= " "
$servername4= " "
$servername5= " "
$servername6= " "
$LUN= " "
$volumename= " "
NEW-SCVolumeMap -ServerName $servername1 -LUN $LUN -VolumeName $volumename
NEW-SCVolumeMap -ServerName $servername2 -LUN $LUN -VolumeName $volumename
NEW-SCVolumeMap -ServerName $servername3 -LUN $LUN -VolumeName $volumename
NEW-SCVolumeMap -ServerName $servername4 -LUN $LUN -VolumeName $volumename
NEW-SCVolumeMap -ServerName $servername5 -LUN $LUN -VolumeName $volumename
NEW-SCVolumeMap -ServerName $servername6 -LUN $LUN -VolumeName $volumename
WRITE-HOST $volumename "has been mapped"
CyberMartyr - Here is the script I'm trying to make work, works fine command line, the foreach variables don't work in the script though, only command line:
Clear-Host
Write-Host "Map a volume to multiple VMWare Servers"
Write-Host "---------------------------------------"
Write-Host
$site = Read-Host -Prompt "Please enter the hostname or ip address for the Compellent Storage Center you want to map VMWare volumes from in lower case."
Write-Host
$serverarray = Read-Host -Prompt "Please list the servers you wish to map this volume to comma separated no spaces in quotes per host"
Write-Host
$volname = Read-Host -Prompt "Please enter the volume name you wish to map to ($serverarray)"
Write-Host
$vollunid = Read-Host -Prompt "Please enter the LUN number you wish to use for $volname"
Write-Host "Site Connection:"
$site
Write-Host
Write-Host "Servers to map:"
$serverarray
Write-Host
Write-Host "Volume Name being mapped:"
$volname
Write-Host
Write-Host "LUN number:"
$vollunid
Write-Host
$serverarray | foreach { New-SCVolumeMap -ConnectionName "$site" -VolumeName "$volname" -ServerName $_ -LUN "$vollunid" }
garyhay - CMonfet's script would be best but its not very efficient.
Assuming you have a standard naming convention for your vmware servers.
I'd reuse his script but change the servername and mappin sections to loops.
build an array of your servers based on their common name and then loop through them to map the volumes.
CyberMartyr - The only problem I'm having with my script is the server array is not propagating during execution time properly and if I modify his script I'm going to have the same issue.
jbraun - Doug,
Using Read-Host returns a string value; that means if you enter "Server1,Server2,Server3" that is exactly what is going to be passed in.
You'll need to convert that string to an array using the "Split" method. So:
# this will separate the individual values into an array using a comma as the delimiter
$servers = $serverarray.Split(',')
If you output $servers you'll get:
Server1
Server2
Server3
in an array instead of:
"Server1,Server2,Server3"
Then your code would look like this:
$servers | foreach { New-SCVolumeMap -ConnectionName $site -VolumeName $volname -ServerName $_ -LUN $vollunid }
Hope this helps.
Best,
Justin
CyberMartyr - Here is my updated code that I'm going to try. Unfortunately I don't have any new requests to try this against:
Clear-Host
Write-Host "Map a volume to multiple VMWare Servers"
Write-Host "---------------------------------------"
Write-Host
$site = Read-Host -Prompt "Please enter the hostname or ip address for the Compellent Storage Center you want to map VMWare volumes from in lower case."
Write-Host
$serverarray = Read-Host -Prompt "Please list the servers you wish to map this volume to comma separated no spaces in quotes per host"
Write-Host
$volname = Read-Host -Prompt "Please enter the volume name you wish to map to ($serverarray)"
Write-Host
$vollunid = Read-Host -Prompt "Please enter the LUN number you wish to use for $volname"
Write-Host "Site Connection:"
$site
Write-Host
Write-Host "Servers to map:"
$serverarray
Write-Host
Write-Host "Volume Name being mapped:"
$volname
Write-Host
Write-Host "LUN number:"
$vollunid
Write-Host
# this will separate the individual values into an array using a comma as the delimiter
$servers = $serverarray.Split(',')
$serverarray | foreach { New-SCVolumeMap -ConnectionName "$site" -VolumeName "$volname" -ServerName $_ -LUN "$vollunid" }
jbraun - Make sure you actually pipe in $servers not $serverarray into the foreach.
Justin
garyhay - in my workplace we have a standard naming convention for our vmware hosts, the way i do this myself is with 2 foreach loops which maps a series of volumes to the vm hosts. for the sake of this post lets say our hosts all contain the letters 'VM' and our volumes all contain the word datastore.
$Servers = get-svserver | ? {$_.name -like "*VM*"}
$Volumes = get-scvolume | ? {$_.name -like "*Datastore*"}
foreach ($Server in $Servers)
{
foreach ($Volume in $Volumes)
{new-scvolumemap -servername $server.name -volumename $volume.name}
}
If you use a tool like quests powergui script editor and import the vsphere powercli module then you can also create the datastores in the same script.
Ill post the actual script I use when im back in work as i also import a csv file to bulk create the volumes before mapping them.
Responses (0)
Solutions (0)
