OK, I am stumped here. I need to destroy one VMFS datastore and add the released LUN to another datastore as an extent.
-
# Get SharedTMPLs disk reference<br /><br/> $esxMoRef = $scHost | % {get-View $_.Id}<br/><br/> $esxStorageSystem = $esxMoRef.configManager.StorageSystem<br/><br/> $esxStorageSystemMoRef = get-View $esxStorageSystem<br/><br/> $ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost | get-View<br/><br/> $lun = $ds.info.vmfs.extent[0].DiskName<br/><br/> $HostDiskPart = New-Object VMware.Vim.HostScsiDiskPartition<br/><br/> $HostDiskPart.diskName = $lun<br/><br/> $hostDiskPart.partition = 26<br/><br/> <br/><br/> ## Destroy SharedTMPLs datastore remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false<br/><br/> start-Sleep -s 10<br/><br/> <br/><br/> ## Add SharedTMPLs disk space to SharedVMs
$ds = get-Datastore -name 'SharedVMs' -VMhost $scHost | get-View $lunVM = $ds.info.vmfs.extent[0].DiskName<br /><br/> $esxStorageSystemMoRef.attachVmfsExtent($lunVM, $HostDiskPart)<br/><br/>
-
I think this should work but Google could not find any examples of doing this. The error I get is
Exception calling "AttachVmfsExtent" with "2" argument(s): "A specified parameter was not correct."<br /><br/> At line:1 char:40<br/><br/> + $esxStorageSystemMoRef.attachVmfsExtent <<<< ($lunVM, $HostDiskPart)<br/><br/> + CategoryInfo : NotSpecified: (:) [], MethodInvocationException<br/><br/> + FullyQualifiedErrorId : DotNetMethodException
</p></p> <p><p>---------------------------------------------------------------------------------------------------------------- </p></p> <p><p>The DotNetMethodException seems to be a bit of a catch all when things don't go well. I tried a brand new powercli window (just to make
sure the problem wasn't some clutter hanging around) but the same thing. Help Please!Thanks,
Carl L. <br /><br/>
</p>
I came up with something similar.
Wouldn't have posted it since you gave your solution, but it shows how to get the correct Uuid.
For info, the script adds the LUN from DS4 to DS3 as an extent.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Carl,
Let's try to diagnose the problem. I need you to create an error report and attach it in a reply-post here so I can get some debugging-level information.
In order to create the error report you have to assign your script to a script-block variable and pass it as a parameter to the Get-ErroReport cmdlet:
$scriptBlock = {
Your script here:
Get SharedTMPLs disk reference
$esxMoRef = $scHost | % {get-View $_.Id}
... etc ...
$esxStorageSystemMoRef.attachVmfsExtent($lunVM, $HostDiskPart)
}
Get-ErrorReport -ProblemDescription "attachVmfsExtent returns an unexpected error" -ProblemScriptTimeoutSeconds 300 -Destination C:\ErrorReports -ProblemScript $scriptBlock -DontIncludeServerLogs
After executing the above script, you'll get a .zip file in the C:\ErrorReports folder. Please attach the file here so I can take a look at it.
Regards,
-Angel
Angel,
Thanks but get-errorReport returns a "CommandNotFound" exception.
Carl L.
That indicates that you are probably not running PowerCLI 4.1.
Can you check with
Get-PowerCLIVersion
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is likely correct. It should be PowerCLI 4.0. The get-powerCliVersion also returns commandNotFoundException. I cannot upgrade to 4.1.
Carl L.
I never was able to get the attachVmfsExtent working, but I always thought it was because my lab uses iScsi storage.
With the ExtendVmfsDatastore method it works for me.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ahh yes, but that is a 4.1 feature. I am stuck in 4.0 and that method is not there.
Carl L.
I don't think so. ExtendVmfsDatastore has been around since API 2.0.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ahh, the downside of still learning. Did not invoke get-view correctly on the datastore. OK, I have this code now but still no joy. Do you have an example that I could work from. I think I am really close.
# Get SharedTMPLs disk reference $esxMoRef = $scHost \| % {get-View $_.Id} $esxStorageSystem = $esxMoRef.configManager.StorageSystem $esxStorageSystemMoRef = get-View $esxStorageSystem $ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost \| get-View $SharedTMPLs = new-Object VMware.Vim.VmfsDatastoreExtendSpec $SharedTMPLs.Extent = $ds.info.vmfs.extent # Lun should be naa.60060160eb702600d845dba3a40adf11 on the Orange kit # Destroy SharedTMPLs datastore remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false start-Sleep -s 1 # Add SharedTMPLs disk space to SharedVMs $sharedVMsDS = get-Datastore -name 'SharedVMs' -VMhost $scHost \| get-View $dsView = get-view $scHostView.configManager.DatastoreSystem $dsView.extendVmfsDatastore($sharedVMsDS, $SharedTMPLs) |
I am getting the error
Cannot convert argument "0", with value: "SharedVMs", for "ExtendVmfsDatastore" to type "VMware.Vim.ManagedObjectReference": "Cannot convert the "SharedVMs" value of type "VMware.VimAutomation.Client20.DatastoreImpl" to type "VMware.Vim.ManagedObjectReference"." At line:1 char:28 + $dsView.extendVmfsDatastore <<<< ($sharedVMs, $SharedTMPLs) + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
Thanks!
Carl L.
Hi Carl,
because the error message tells you that it needs a MoRef, I changed line 12 to get the MoRef of the datastore. I hope this will solve your problem.
# Get SharedTMPLs disk reference $esxMoRef = $scHost | % {get-View $_.Id} $esxStorageSystem = $esxMoRef.configManager.StorageSystem $esxStorageSystemMoRef = get-View $esxStorageSystem $ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost | get-View $SharedTMPLs = new-Object VMware.Vim.VmfsDatastoreExtendSpec $SharedTMPLs.Extent = $ds.info.vmfs.extent # Lun should be naa.60060160eb702600d845dba3a40adf11 on the Orange kit # Destroy SharedTMPLs datastore remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false start-Sleep -s 1 # Add SharedTMPLs disk space to SharedVMs $sharedVMsDS = (get-Datastore -name 'SharedVMs' -VMhost $scHost).Id $dsView = get-view $scHostView.configManager.DatastoreSystem $dsView.extendVmfsDatastore($sharedVMsDS, $SharedTMPLs)
Regards, Robert
I came up with something similar.
Wouldn't have posted it since you gave your solution, but it shows how to get the correct Uuid.
For info, the script adds the LUN from DS4 to DS3 as an extent.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference