Hello,
I have tried performing SVmotion via vSphere Power CLI and it is working great.
But while performing the SVmotion I also want to mention the DISK FORMAT i.e. "thin" ... While doing the SVmotion I want the disk to be THIN DISK PROVISIONED.
Move-VM -VM (Get-VM -Name litbuildvm ) -Datastore <Datastore Name>
Can anyone help out her, Now in the above command, say the source vmdk is THICK provisioned after SVmotion it still remains thick.
But I want to make the source vmdk disk which is THICK to THIN after SVmotion in the vSphere CLI.....
Please help
deepak
Yes, that's correct.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at Move-VMThin SVMotion.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LuCD,
Thanks but I dont get it, is there no single command or possible using Power CLI.
How should I make use of this Powershell Script.... ? ? and they say it can be used only for a single VM....
LuCD, I am rather looking to automate SVmotion based on the datastore usage.... So I will have to do a bulk SVmotion.....
Any thoughts ?
deepak
Deepak,
The function can be used as a filter in the pipeline sequence.
function Move-VMThin {
param(
[ValidateNotNullOrEmpty()]
[http://System.String|http://System.String]$VM
,
[ValidateNotNullOrEmpty()]
[http://System.String|http://System.String]$Datastore
)
Begin {
#Nothing Necessary to process
} #Begin
Process {
#Prepare Migration info, uses .NET API to specify a transformation to thin disk
$vmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = "$VM"}
$dsView = Get-View -ViewType Datastore -Filter @{"Name" = "$Datastore"}
#Abort Migration if free space on destination datastore is less than 50GB
if (($dsView.info.freespace / 1GB) -lt 50) {Throw "Move-ThinVM ERROR: Destination Datastore $Datastore has less than 50GB of free space. This script requires at least 50GB of free space for safety. Please free up space or use the VMWare Client to perform this Migration"}
#Prepare VM Relocation Specificatoin
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = $dsView.MoRef
$spec.transform = "sparse"
#Perform Migration
$vmView.RelocateVM($spec, $null)
} #Process
}
Get-VM | Move-VMThin -Datastore "MyDS"
The above example svMotions all guests to datastore "MyDS" and converts the virtual hard disks to the Thin type.
You can of course change the selection criteria for the guests
To only svMotion guests whose name starts with "PC"
... Get-VM "PC*" | Move-VMThin -Datastore "MyDS"
To select the destination datastore depending on the name of the guest.
...
Get-VM | %{
if($_.Name -like "PC*"){
$_ | Move-VMThin -Datastore "PcDS"
}
elseif($_.Name -like "SRV*"){
$_ | Move-VMThin -Datastore "SrvDS"
}
}
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LuCD
ok so you are telling that my powershell script should have the function "Move-VMThin" ...
And I have to use "Move-VMThin" instead of "Move-VM" so that the SVmotion will convert my disks to THIN after the migration...
Is that correct LuCD ?
Deepak
Yes, that's correct.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LuCD you rock man ![]()
Thanks, I will let you know once I have written the script.... I have marked as Correct Answer...
Can you please help me with the 3 below questions I have ....
Can you tell me is there any VMware link or Bugzilla where we can post any bugs we have encountered ?
Can we post our own written vSphere Power CLI scripts in VMware site... so that it can help the other users as well.....?
Where can I mention feature enhancements for vSphere in VMware ?
Deepak
If you find a bug I think the best procedure is to open a Support Request.
You can post your scripts in the PowerCLI Community under the Documents tab.
There are quite a number of VMware people reading the community posts.
So I think you could just post your suggestions/ideas in the PowerCLI Community.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Deepak,
There is also a VMware Community Product & Feature Suggestions. Might be a good place to post feature enhancements for vSphere.
Robert
Thanks LuCD and Robert, for those helpful answers. ![]()
Deepak
Ooops!!! I am stuck,
LuCD, you had given me a SVmotion-Thin function... I did not find time to execute and give a try...I tried today... in the PowerGUI ... the script is as how I have used it below
function Move-VMThin {
param(
,
http://System.String$Datastore
)
Begin {
#Nothing Necessary to process
} #Begin
Process {
#Prepare Migration info, uses .NET API to specify a transformation to thin disk
$vmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = "$VM"}
$dsView = Get-View -ViewType Datastore -Filter @{"Name" = "$Datastore"}
#Abort Migration if free space on destination datastore is less than 50GB
if (($dsView.info.freespace / 1GB) -lt 50) {Throw "Move-ThinVM ERROR: Destination Datastore $Datastore has less than 50GB of free space. This script requires at least 50GB of free space for safety. Please free up space or use the VMWare Client to perform this Migration"}
#Prepare VM Relocation Specificatoin
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = $dsView.MoRef
$spec.transform = "sparse"
#Perform Migration
$vmView.RelocateVM($spec, $null)
} #Process
}
Connect-VIServer -Server XXXX -User YYYYY -Password ZZZZZ
Get-VM "lrhel120" | Move-VMThin -Datastore "Clar-34"
I want to SVmotion thin of the VM lrhel120 to Clar-34 ..... The script is not getting executed, It says "Starting script execution" and nothing is shown in the "PowerShell console" window...
Any idea what is the issue... i have also tried giving the "Connect-VIServer" before the function "Move-VMThin" but still the same
please suggest
Deepak
There was a parameter option (ValueFromPipeline) missing in the script.
Can you try it with the attached script ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Can I ask you couple questions, please?
1. When I am trying to run your script I got error:
Method invocation failed because [System.Object[]] doesn't contain a method named 'RelocateVM'.
At :line:32 char:20
+ $vmView.RelocateVM <<<< ($spec, $null)
do you know what is wrong?
2. Where in the script specified that new (moved) vmdk will be "thin"? Is it based on
"$spec.transform = "sparse" parameter? How should I change it if I want to move from thin to thick?
Tthanks a lot!
1) How did you call the function ?
Something like this ?
Move-VMThin -VM MyVM -Datastore MyDS
2) Yes, "sparse" indicates the destination VMDK should be in the Thin format.
The possible values, only 2, are described in the VirtualMachineRelocateTransformation enumeration.
For the transform to Thick use the value "flat"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
1. I call the function like that:
Get-VM -Name "vmname" | Move-VMthin -Datastore "datastoreName"
and now it's working just fine.
2. Thanks a lot for "flat" format tip!
Thank you very much for your help!
