VMware Cloud Community
Gyan198902
Contributor
Contributor
Jump to solution

Get VMx path and then reregister

I need command  to get the vmx file path and current running esxi host location for a list of Vm(VM list from a text file or a CV)

Then i am going to manually unregister them all(all vm above)

Also i need a scripts to reregister above VMs back to same Vcenter cluster and hosts and then power on, please help

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can find the VMX of a VM with the following.

Get-VM |
Select-Object Name, @{N = 'VMX'; E = { $_.ExtensionData.Summary.Config.VmPathName}}

If you are looking for a specific set, you can use the Name property on Get-VM

Get-VM -Name (Get-Content -Path .\vmnames.txt) |
Select-Object Name, @{N = 'VMX'; E = { $_.ExtensionData.Summary.Config.VmPathName}}

Unregistering is done via the Remove-VM cmdlet with the DeletePermanently switch set to $false.
Registering is done via the New-VM cmdlet with the VMFilePath parameter. 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You can find the VMX of a VM with the following.

Get-VM |
Select-Object Name, @{N = 'VMX'; E = { $_.ExtensionData.Summary.Config.VmPathName}}

If you are looking for a specific set, you can use the Name property on Get-VM

Get-VM -Name (Get-Content -Path .\vmnames.txt) |
Select-Object Name, @{N = 'VMX'; E = { $_.ExtensionData.Summary.Config.VmPathName}}

Unregistering is done via the Remove-VM cmdlet with the DeletePermanently switch set to $false.
Registering is done via the New-VM cmdlet with the VMFilePath parameter. 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Gyan198902
Contributor
Contributor
Jump to solution

Thank you so much added vmxhost and able to export hostname to csv.

Get-VM -Name (Get-Content -Path .\vmnames.txt) |
Select-Object Name, @{N = 'VMX'; E = { $_.ExtensionData.Summary.Config.VmPathName}}, VMHost | Export-csv -Path C:\Report.csv -NoTypeInformation -UseCluture

Working on 2nd part for taking details from csv and registering back to vcenter after i unregister it.

If you have any script please help

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like this

Import-Csv -Path C:\Report.csv -UseCulture |
ForEach-Object -Process {
    Get-VM -Name $_.Name | Remove-VM -DeletePermanently:$false -Confirm:$false

    New-VM -VMFilePath $_.VMX -Confirm:$false 
} 

On the New-VM you could add for example a VMHost


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos