I use ESXi 5.0 with 3 datastores. For example, datastore1, datastore2, datastore3
When I use
$vm2 = New-VM -Name $dvm -VM $vm -ResourcePool 'Tech' -Location 'Tech' -Confirm:$false
to clone a new VM, it will clone a VM which stores in datastore2.
But if I use
$DS = Get-Datastore -Server serverip 'datastore2'
$vm2 = New-VM -Name $dvm -VM $vm -ResourcePool 'Tech' -Location 'Tech' -Datastore $DS -Confirm:$false
It failed and reported no privilege.
Is there any wrong in my script?
Thanks,
Are you by any chance using datastoreclusters ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am not sure. It's maintained by other people.
Is there any suggestion?
Does
Get-DatastoreCluster
return anything ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nothing.
So Cluster is not used. Right?
Apparently not.
Did you already leaving out the Server parameter on the Get-Datastore cmdlet ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you mean Get-DatastoreCluster? Yes.
No, on the Get-Datastore you did before your 2nd New-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's very strange. Yesterday I use the code without server parameter, it can clone a new VM but the process in PowerGUI always in 0%. But I try it today it report no privilege gain.
Is the command perhaps waiting for a parameter ?
Any error messages ?
Did you try the same without a RunAsync (if you are using that parameter of course).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I didn't change any code, but it works now. No error report again.
I didn't change any code but this issue occurs again.
+ $vm2 = New-VM <<<< -Name $dvm -VM $VM -ResourcePool $RS -Location 'Tech_Team' -Datastore $DS -DiskStorageFormat Thin
-Confirm:$false
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
Can you include the details of the exception ?
Perhaps that gives some more info.
$error[0].Exception | select *
$error[0].Exception.InnerException | select *
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks.
The error message changed again. Now it report Operation is not valid due to the current state of the object.
PS D:\Script> $Error[0].exception | select *
ErrorId : Core_BaseCmdlet_UnknownError
ErrorCategory : NotSpecified
TargetObject :
RecommendedAction : Error occured while executing cmdlet: New-VM. Check inner exception for more details.
SessionId :
ConnectionId :
Severity : Error
Message : 8/17/2012 10:59:27 AM New-VM Operation is not valid due to the current state of t
he object.
Data : {ParameterValues}
InnerException : System.InvalidOperationException: Operation is not valid due to the current state of the ob
ject.
at VMware.VimAutomation.ViCore.Impl.V1.Task.ViCoreTaskCoreServiceProviderImpl.BeginTaskC
ompletionPoll(List`1 taskList)
at VMware.VimAutomation.Sdk.Impl.V1.Task.CoreTaskServiceImpl.WaitForTask(IEnumerable`1 t
askList, ProgressCallback progressCallback)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.EndProcessingErrorHandled()
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.EndProcessingErrorHandled(
)
TargetSite : Void ThrowTerminatingError(System.Management.Automation.ErrorRecord)
StackTrace : at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord erro
rRecord)
HelpLink :
Source : System.Management.Automation
PS D:\Script> $Error[0].exception.innerexception | select *
Message : Operation is not valid due to the current state of the object.
Data : {}
InnerException :
TargetSite : Void BeginTaskCompletionPoll(System.Collections.Generic.List`1[VMware.VimAutomation.Sdk.Intero
p.V1.Task.TaskInterop])
StackTrace : at VMware.VimAutomation.ViCore.Impl.V1.Task.ViCoreTaskCoreServiceProviderImpl.BeginTaskComp
letionPoll(List`1 taskList)
at VMware.VimAutomation.Sdk.Impl.V1.Task.CoreTaskServiceImpl.WaitForTask(IEnumerable`1 task
List, ProgressCallback progressCallback)
at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.EndProcessingErrorHandled()
at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.EndProcessingErrorHandled()
HelpLink :
Source : VMware.VimAutomation.ViCore.Impl
It looks as if one of the objects involved in the cloning process is in a funny state.
Are the VM from which you clone and the target datastore available and running correctly ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, they are available and running correctly.
And if I clone the VM(store in the same datastore) and let New-VM use this VM as source VM, PowerCLI will report same error, but it can clone the VM.
Strange, perhaps the PowerCLI Dev Team has some ideas ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
