Hi Luc,
i need to register vms which are shown by below code with corresponding datastore .can you please complete below code .
$csv_info = Import-Csv c:\servers.csv
foreach ($line in $csv_info) {
$x=get-vm $line.vmname
$datastore=get-vm $x|get-datastore
[pscUSTOMoBJECT]@{
vmname = $x.name
datastorename = $datastore.name
}
}
Or you could read my first reply correctly, which was based on the original code you posted.
$datastore and $x were the full objects, not just the Name property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm not getting the question I'm afraid.
You want to register a VM, but the VM seems to be already registered (judging from the Get-VM you are doing).
To register an orphaned VM you will need the path to the .VMX file.
Something like this for example
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
if yu can check the below scenerio.
one host in non responding state in vcenter .
tech support asked to generate core dump .
so we need to shut down vm and register to other hosts(host in vcenter )
and then generate core dump .
Still confused, you can vMotion a VM to another ESXi node.
Registering a VM is done on the vCenter afaik.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
host is not responding in vcenter so drs and vmotion wont work .
i was thinking of HA but that will restart vms non gracefully.
i think below script should work .it will remove from inventory and register to new host .
$csv_info = Import-Csv c:\servers.csv
$dlist= @()
foreach ($line in $csv_info) {
$x=get-vm $line.vmname
$datastore=get-vm $x|get-datastore
$D = $datastore.name
$dlist += $D
remove-vm $x
New-Vm -DiskPath "[$($datastore.Name)] $($x.Name)/$($x.Name).vmx" -VMHost "xyz"
[pscUSTOMoBJECT]@{
vmname = $x.name
datastorename = $datastore.name
}
}
I'm not sure that will work when that host is not responding.
Or are you moving away from the non-responsive host?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
so what we will do is to shutdown all vms gracefully through rdp
then unregister it from vcenter as they are added to vcenter
we will add them back to responsive host .so moving away from non responsive host ...
if yu can validate in yur lab the script which i sent ..
That should work, provided you do the Get-VM before you unregister the VM.
But you could just as well do a Move-VM after the VM is powered off (provided there is no lock on any of the VM's files).
This is hard to simulate in a lab.
A powered-off ESXi node is not the same as a non-responsive ESXi node which still might hold locks on the VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That should work, provided you do the Get-VM before you unregister the VM.
thats why i put remove-vm after get-vm .
i supect lock things but once vm is powered down lock will be realesed i belive .
I HATE LOCKS AND LOCKDOWN :smileycry:
Hi Luc,
iam checking this in lab and new-vm part is not working in below code
$csv_info = Import-Csv c:\servers.csv
$dlist= @()
foreach ($line in $csv_info) {
$x=get-vm $line.vmname
$datastore=get-vm $x|get-datastore
$D = $datastore.name
$dlist += $D
remove-vm $x
New-Vm -DiskPath "[$($datastore.Name)] $($x.Name)/$($x.Name).vmx" -VMHost "xyz"
[pscUSTOMoBJECT]@{
vmname = $x.name
datastorename = $datastore.name
}
}
Is that a VSAN datastore?
What does the following say (while the VM is still registered)?
@{N='VMX';E={$_.ExtensionData.Summary.Config.VmPathName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i figured it out
following worked .it seems i m still able to think in corona pandemic:smileylaugh:
Or you could read my first reply correctly, which was based on the original code you posted.
$datastore and $x were the full objects, not just the Name property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
oh i missed it thanks Luc sir.