vishaln
Enthusiast
Enthusiast

Powercli command to unregister from vCenter 6.7

Hi,

I am looking Powercli command to unregistered/registered Virtual Machine from vSphere 6.7.

0 Kudos
9 Replies
T180985
Expert
Expert

Do you want to also delete from disk or just remove from inventory?

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
0 Kudos
LucD
Leadership
Leadership

Try like this.
Note that this will not delete the VM's files

Get-VM -Name MyM | Remove-VM -DeletePermanently:$false -Confirm:$false


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

0 Kudos
LucD
Leadership
Leadership

Btw, this seems to be the same question you already asked in How to unregister and register Virtual machine vcenter 6.7 via PowerCLI


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

0 Kudos
MattHumphreys
Contributor
Contributor

if you just want to remove it from inventory without deleting from disk do this:

Remove-VM -VM <EnterVM> -Confirm:$false

If you want to delete the VM entirely from disk then do this:

Remove-VM -VM <EnterVM> -DeletePermanently -Confirm:$false

These commands wont ask you for confirmation they will just do it, if you want it to ask you before doing it just remove the -Confirm:$false

To add the VM back you need some details like the VMX file location, if you run these before you remove the VM from inventory you can gather that info and store it in a variable to use later:

$vmdetails = Get-VM -Name <Enter VM>

$vmname = $vmdetails.Name

$vmfolder = $vmdetails.Folder

$vmxfile = $vmdetails.ExtensionData.config.Files.VmPathName

Then to add the VM back to the folder it was in before:

New-VM -VMFilePath $vmxfile -Location $vmfolder

To start the VM use:

Get-VM -Name $vmname | Start-VM -RunAsync

I have assumed you have already connected the the vcenter server before running these commands.

0 Kudos
vishaln
Enthusiast
Enthusiast

That didn't work.

0 Kudos
vishaln
Enthusiast
Enthusiast

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

What didn't work?

Your vSphere connection does not work.
Does your Connect-VIServer work?

And why did you create a new thread?


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

0 Kudos
vishaln
Enthusiast
Enthusiast

What didn't work? command which provided for re-register

Your vSphere connection does not work.
Does your Connect-VIServer work? I am able to connect VIserver

And why did you create a new thread? I forgot the preview request I already did, sorry for that

0 Kudos
LucD
Leadership
Leadership

That first error message seems to say otherwise, i.e. that you are not connected or that the connection has an issue.

Can you run a regular command?

Like

Get-VM -Name Testing-VSNARSE


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

0 Kudos