VMware Cloud Community
flipster
Contributor
Contributor
Jump to solution

Find unregistered virtual machines

Hi,

Does anyone know/have a way to find unregistered virtual machines?

Thanks in advance!

Tags (2)
0 Kudos
54 Replies
LucD
Leadership
Leadership
Jump to solution

Gurjit, it seems you are looking for a script that finds left-over entries for VMs that have been removed ?

That's the only situation where I can see a VM folder without a VMX file being present.

Is my assumption correct ?


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

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi,

Let me once again clear you my points, there are 2 scripts I am looking for.

First, list of VM which are not registered along with datastore name and report on xls file.

Secound, Find out all the VM's which dont have VMX file on any of the datastore and report on xls file.

your script works nicely, but it displays only datastore name, I am also looking for VM name along with datastore name in Xls file. Is that possible to modify this script to also show the Vm name, Vm name can be extrated from the Vmx file, example: test-vm.vmx , here vm name will come out as test-vm or vm name can be extrated from the directory where vmx file resides, example: test-vm/test-vm.vmx or it is also ok to list the vm name as vmname.vmx without any extration, example vm-test.vmx.

I believe I have made you understart my points.

Regards

Gurjit Dhillon

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hi,

I just executed your script "Find-unregistered-VMX-with-CSV-v3.ps1", It sharted showing me the list of datastore name, but at the end it faied to generate the report along with the error below. hope it must be minor change.

Cannot bind argument to parameter 'InputObject' because it is null.

At :line:60 char:20

+ $report | Export-Csv <<<< "C:\Unregistered-VMX.csv" -NoTypeInformation

Regads

Gurjit Dhillon

0 Kudos
johthi
Enthusiast
Enthusiast
Jump to solution

Hi,

Can you try this tool....

"searchmyvm" its a free tool, you can download from www.vkernel.com

You can create your own query in this tool and get output from excel sheet.

Try this tool and let me know

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

thanks, sure i will try this.

Regards

Gurjit Dhillon

0 Kudos
gurjitd
Contributor
Contributor
Jump to solution

Hello Luc,

I just saw a video TA01 - Managing VMware With PowerShell Part I at http://www.vimeo.com/3469291, where you were getting appricated for your support and dedication. I was not know you were so big personallity.

Its really nice see people like you helping numbers of people to achive there goal.

I Wish you all of your wishes comes true. Smiley Happy

Regards with love

Gurjit Dhillon

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Gurjit, the file "Find-unregistered-VMX-with-CSV-v3.ps1", indeed had an error in it.

The $datastorepath was not set correctly.

Attached a new version that should now have a working script.

PS: I suggest you open 2 new threads with your 2 specific questions.

It's difficult to find for others if we keep adding this to this thread that started with another question.


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

admin
Immortal
Immortal
Jump to solution

LucD, Are you sure your script works? I don't see that it every runs the inner "if" if($result.File -ne $null) ?

I do know that it doesn't report orphans I know about.

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're absolutely right. Well spotted.

There was a typo in the previous foreach statement.

The attached file is now updated.


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

0 Kudos
flipster
Contributor
Contributor
Jump to solution

Hi LucD,

Can you kindly re-attach the correct version? I'm still getting the same error.

Thanks Sir!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Apparently it wasn't my day yesterday Smiley Sad

The attached file above (Find-unregistered-VMX-with-CSV-v4.ps1) should now be the correct version.

Sorry about that.


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

0 Kudos
admin
Immortal
Immortal
Jump to solution

Why do you skip NFS datastores?

Where can I find documentation on VMware.Vim.HostDatastoreBrowserSearchSpec ?

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The NFS was skipped because I have a rather big NFS datastore and the test run of the script would take too long.

You may remove that line.

The HostDatastoreBrowserSearchSpec is described in the SDK.


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

0 Kudos
admin
Immortal
Immortal
Jump to solution

LucD,

Sorry to keep bothering you, but I'm trying to work my way through the script (I does some of what I want but not all) but I can't seem to figure some of it out.

Right at the beginning, this piece prints the name of one of the two datacenters, then prints the name of the other datacenter and works through its clusters. I don't see that it ever works through the cluster it lists first.

Get-Datacenter | % {

$datacenter = $_

Write-Host "Datacenter" $_.Name

$folder = Get-View ($_ | Get-Folder -Name "vm").ID

$_ | Get-Cluster | % {

$cluster = $_

I plan on setting it up so it only checks datastores once, doesn't check NetApp Snapshots (any .snapshot directory) and also checks for orphan vmdks.

Thanks for the help

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The script consists of several nested loops (the foreach, alias %, constructs).

The outer loop is taken for each datacenter object that Get-Datacenter places on the pipeline.

The 2nd loop is for each cluster in the datacenter from loop 1.

Did you check if the loops are correct ?

Are the blocks (the { } constructs) correct ?

You should see a structure similar to this

Get-Datacenter | % {  		                        # Start datacenter loop
	$datacenter = $_
	Write-Host "Datacenter" $_.Name
	$folder = Get-View ($_ | Get-Folder -Name "vm").ID
	$_ | Get-Cluster | % {	                        # Start cluster loop
		$cluster = $_
		...
	}						# End cluster loop
	...
}							# End datacenter loop

I'm not sure what editor you are using for your PS scripts but there are several that check the loop constructs for you.

And there are some (for example PowerShell Plus or EcoShell) that allow you to step through the script line by line and inspect the variables.


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

0 Kudos
admin
Immortal
Immortal
Jump to solution

I see my problem, that data center contains hosts but no clusters and PrimalScope wasn't stepping to the cluster loop.

Thanks again.

0 Kudos
admin
Immortal
Immortal
Jump to solution

My take on the script. I removed some lines that didn't matter to the script, added in not searching a datastore more than once and some other checks plus a boilerplate menu to choose which vCenter server to use.

I added a few comments also incl a list of assumptions.

next step, checking orphan VMDKs and checking all hosts in a cluster to make sure all see the same datastores.

0 Kudos
mdpete4
Contributor
Contributor
Jump to solution

This is exactly what I've been looking for but for some reason when I run it I get "Get-Datacenter is not a recognized cmdlet". I must be doing something wrong or do not have the correct set of cmdlet's. I'm an extreme newbie (day 1) so go easy!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you load the PowerCLI snapin ?

Add-PSSnapin VMware.VimAutomation.Core

You can check with

Get-PSSnapin

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
mdpete4
Contributor
Contributor
Jump to solution

I guess I haven't loaded it. I ran the Add-PSSnapin... bit and then the check but the vmware snapin does not show up. I'll look around for threads on adding the snapin since it sounds like that is my problem. Thanks for the reply!

0 Kudos