Page 1 of 1
Powershell - How to attach existing device to existing storage
Posted: Tue Mar 27, 2018 3:53 pm
by hjgl
Hi all,
I was searching how to attach a new disk to my existing storage in PS, but i can't find documentation about this. In PS examples files (CreateImageFile.ps1), when i run this script, this dettach all devices and then attach the new one.
Anybody can help me? Thanks in advance.
Re: Powershell - How to attach existing device to existing storage
Posted: Tue Mar 27, 2018 4:09 pm
by Boris (staff)
Could you be more specific on "attach a new disk to my existing storage"? What scenario is meant by this?
Re: Powershell - How to attach existing device to existing storage
Posted: Tue Mar 27, 2018 5:11 pm
by hjgl
hjgl wrote:Hi all,
I was searching how to attach a new disk to my existing storage in PS, but i can't find documentation about this. In PS examples files (CreateImageFile.ps1), when i run this script, this dettach all devices and then attach the new one.
Anybody can help me? Thanks in advance.
Oh i'm sorry, i'm not english speaker. My setup is stand alone in windows 2012 on test environment. I want create a new virtual disk in my storage, called "vSAN". This "vSAN" have 17 virtual disk working fine and i want add one more. When i ran the CreateImageFile.ps1 script, this script dettach all my virtual disks and then attach only the new one.
My Script is this:
Import-Module StarWindX
try
{
$server = New-SWServer -host 127.31.0.6 -port 3261 -user root -password starwind
$server.Connect()
#create image file
New-ImageFile -server $server -path "My Computer\D\VM\Shared Storage\SQLData05" -fileName "imagefile18" -size 120
#create device
$device = Add-ImageDevice -server $server -path "My Computer\D\VM\Shared Storage\SQLData05" -fileName "imagefile18" -sectorSize 512 -NumaNode 0
#create target
$target = New-Target -server $server -alias "vSAN" -devices $device.Name
#$target
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
If i skip the "Create Target" label, then the disk is created but not attached to the "vSAN" storage. Please, help.
Re: Powershell - How to attach existing device to existing storage
Posted: Wed Mar 28, 2018 8:55 am
by Boris (staff)
What is the build number you currently use and encounter this behavior? Do you have all 17 virtual disks attached to the same vSAN target? If so, this should not be so. I would recommend using 1 disk per 1 target.
Re: Powershell - How to attach existing device to existing storage
Posted: Wed Mar 28, 2018 2:33 pm
by hjgl
The build number is the most recent (i just download the last weekend) 8.0.0.11818. Yes, the 17 virtual disk are attached to the same vSAN target and i believe this setup is right because is a SQL Server cluster with many mount points. The setup work fine and the cluster run fine, but i can't create a new vdisk and attach to the same vSAN for dev and research purpoise. Can you help me with this? I only need the code in PS for create and attach a new vdisk.
Re: Powershell - How to attach existing device to existing storage
Posted: Thu Mar 29, 2018 3:19 pm
by Boris (staff)
Do you use a standalone setup?
If so, this script can help you:
Code: Select all
import StarWindX
try
{
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
#create image file
#size in megabytes
New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
#create device
$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
#create target
$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a
workaround developed specifically for your case, but
not an
official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
Re: Powershell - How to attach existing device to existing storage
Posted: Mon Apr 02, 2018 3:15 pm
by hjgl
Boris (staff) wrote:Do you use a standalone setup?
If so, this script can help you:
Code: Select all
import StarWindX
try
{
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
#create image file
#size in megabytes
New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
#create device
$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
#create target
$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a
workaround developed specifically for your case, but
not an
official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
Thank you for your help. This have an issue: the $server.Devices[] array is empty, so i couldn't attach the disks again (neither the new one 18). I get your idea and it's good because is an experimental and dev environment, but have this issue.
Re: Powershell - How to attach existing device to existing storage
Posted: Mon Apr 02, 2018 3:39 pm
by hjgl
hjgl wrote:Boris (staff) wrote:Do you use a standalone setup?
If so, this script can help you:
Code: Select all
import StarWindX
try
{
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
#create image file
#size in megabytes
New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
#create device
$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
#create target
$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a
workaround developed specifically for your case, but
not an
official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
Thank you for your help. This have an issue: the $server.Devices[] array is empty, so i couldn't attach the disks again (neither the new one 18). I get your idea and it's good because is an experimental and dev environment, but have this issue.
Ready, thanks a lot! The workaround was set the device name hardcoded like imagefile1,imagefile2,etc and this work great. No shutdown or errors in the cluster manager during the script execution.
I put the script "fixed":
Import-Module StarWindX
try
{
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
#create image file
#size in megabytes
New-ImageFile -server $server -path "My Computer\D" -fileName "imagefile18" -size 10240
#create device
$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "imagefile18" -sectorSize 512 -NumaNode 0
#create target
$target = New-Target -server $server -alias "vSAN" -devices imagefile1,imagefile2,imagefile3,imagefile4,...,imagefile17,imagefile18
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
Re: Powershell - How to attach existing device to existing storage
Posted: Mon Apr 02, 2018 4:04 pm
by Boris (staff)
Nice to learn this worked for you.