<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Find/count VMs with 2 or more VMDKs on different Datastores in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557513#M86755</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering how to find (and count later) all VMs that have 2 or more VMDKs on different datastore...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 May 2010 18:55:14 GMT</pubDate>
    <dc:creator>qwert1235</dc:creator>
    <dc:date>2010-05-05T18:55:14Z</dc:date>
    <item>
      <title>Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557513#M86755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering how to find (and count later) all VMs that have 2 or more VMDKs on different datastore...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 18:55:14 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557513#M86755</guid>
      <dc:creator>qwert1235</dc:creator>
      <dc:date>2010-05-05T18:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557514#M86756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The attached script gets the VM's with vmdk's on more then one datastore.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to attach the script because it contains square brackets and the forum software has problems with them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 19:39:37 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557514#M86756</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2010-05-05T19:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557515#M86757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This script worked great for me.  Simple script and it tells you the "VMNAME, DATASTORE, Cluster".  If a VM has 2 VMDKs, it just lists the VM on 2 lines, obviously 2nd line shows the other VMDK file.  Creates a CSV file in the root of C.  You can change it to whatever you like. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="noformat"&gt;
$report = @() 
$allvms = Get-VM 
foreach ($vm in $allvms) { 
        $clusterName = ($vm | Get-Cluster).Name
        $dstores = $vm | Get-Datastore 
        foreach($ds in $dstores){ 
                $row = "" | select VMNAME, DATASTORE, Cluster 
                $row.VMNAME = $vm.name 
                $row.DATASTORE = $ds.Name 
                $row.Cluster = $clusterName
                $report += $row 
        } 
} 
$report | Export-Csv "C:\VM_DS.csv" -NoTypeInformation 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 19:40:09 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557515#M86757</guid>
      <dc:creator>sm7012</dc:creator>
      <dc:date>2010-05-05T19:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557516#M86758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The attached script counts the VM's with vmdk's on more then one datastore.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to attach the script because it contains square brackets and the forum software has problems with them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Robert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 May 2010 19:40:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557516#M86758</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2010-05-05T19:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557517#M86759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your help!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I like this script very much: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="noformat"&gt;
$report = @() 
$allvms = Get-VM 
foreach ($vm in $allvms) { 
$clusterName = ($vm | Get-Cluster).Name
$dstores = $vm | Get-Datastore 
foreach($ds in $dstores){ 
$row = "" | select VMNAME, DATASTORE, Cluster 
$row.VMNAME = $vm.name 
$row.DATASTORE = $ds.Name 
$row.Cluster = $clusterName
$report += $row 
} 
} 
$report | Export-Csv "C:\VM_DS.csv" -NoTypeInformation 
&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I cannot figure out how to collect only VMs with vmdks different datastore... I know I should use "-Unique" but could not figure out where...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help will be really appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 16:27:07 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557517#M86759</guid>
      <dc:creator>qwert1235</dc:creator>
      <dc:date>2010-05-07T16:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557518#M86760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try to change this line&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;
$dstores = $vm | Get-Datastore 
&lt;/PRE&gt;&lt;P&gt;into this&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;
$dstores = $vm | Get-Datastore | Select-Object -Unique
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;____________&lt;/P&gt;&lt;P&gt;Blog: &lt;A href="http://lucd.info"&gt;LucD notes&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Twitter: &lt;A href="http://twitter.com/lucd22"&gt;lucd22&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 16:37:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557518#M86760</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2010-05-07T16:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557519#M86761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The next script will do the job:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;
$report = @() 
$allvms = Get-VM 
foreach ($vm in $allvms) { 
	$clusterName = ($vm | Get-Cluster).Name
	$dstores = $vm | Get-Datastore 
	foreach($ds in $dstores){ 
		$row = "" | select VMNAME, DATASTORE, Cluster 
		$row.VMNAME = $vm.name 
		$row.DATASTORE = $ds.Name 
		$row.Cluster = $clusterName
		$report += $row 
	} 
} 
$report | `
Sort-Object -Property VMName,Datastore -Unique | `
Group-Object -Property VMName | `
Where-Object { $_.Count -gt 1 } | `
Export-Csv "C:\VM_DS.csv" -NoTypeInformation 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Robert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 16:57:21 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557519#M86761</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2010-05-07T16:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557520#M86762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luc,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No, it did not change anything at all...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I still have report of all VMs with 2 or more vmdks, but if VM has 2 (or more) vmdks on the same datastore it's still listed in the report, but only once... and I do not to have it in the report at all...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 17:10:13 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557520#M86762</guid>
      <dc:creator>qwert1235</dc:creator>
      <dc:date>2010-05-07T17:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557521#M86763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, I see. Got your question wrong then.&lt;/P&gt;&lt;P&gt;Robert's latest script will do what you want.&lt;/P&gt;&lt;P&gt;The where-clause in there will get rid of VMs who are only using 1 datastore.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;____________&lt;/P&gt;&lt;P&gt;Blog: &lt;A href="http://lucd.info"&gt;LucD notes&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Twitter: &lt;A href="http://twitter.com/lucd22"&gt;lucd22&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 17:18:44 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557521#M86763</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2010-05-07T17:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557522#M86764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looks like onle VMs with vmdks on different datastore were selected.  However report does not have any information right now about VMs name, datastore name and cluster... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead it give something like that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;System.Collections.ArrayList,2,System.Collections.ObjectModel.Collection`1[http://System.Management.Automation.PSObject|http://System.Management.Automation.PSObject],myvirtualMachine_name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 17:19:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557522#M86764</guid>
      <dc:creator>qwert1235</dc:creator>
      <dc:date>2010-05-07T17:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557523#M86765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Argh, you will allways see that the only line in my script that I didn't test, the Export-CSV cmdlet, gives you trouble. The next script I tested from the beginning to the end &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.vmware.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt; and gives even better output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;
$report = @() 
$allvms = Get-VM 
foreach ($vm in $allvms) { 
	$clusterName = ($vm | Get-Cluster).Name
	$dstores = $vm | Get-Datastore 
	foreach($ds in $dstores){ 
		$row = "" | select VMNAME, DATASTORE, Cluster 
		$row.VMNAME = $vm.name 
		$row.DATASTORE = $ds.Name 
		$row.Cluster = $clusterName
		$report += $row 
	} 
} 
$report | `
Sort-Object -Property VMName,Datastore -Unique | `
Group-Object -Property VMName | `
Where-Object { $_.Count -gt 1 } | `
Foreach-Object { 
	foreach ($Record in $_.Group) {$Record } 
} | `
Export-Csv "C:\VM_DS.csv" -NoTypeInformation 
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Update: I saw that the first line was missing, so I added the first line to the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: RvdNieuwendijk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 17:38:11 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557523#M86765</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2010-05-07T17:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557524#M86766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's exactly what I was looking for!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;qwert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 18:00:44 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557524#M86766</guid>
      <dc:creator>qwert1235</dc:creator>
      <dc:date>2010-05-07T18:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Find/count VMs with 2 or more VMDKs on different Datastores</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557525#M86767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Inspired by a post by Jason Major, jmajor1111, in thread &lt;SPAN __jive_macro_name="thread" id="267505"&gt;&lt;/SPAN&gt; I came to an even more simple solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;
Get-VM | `
ForEach-Object {
	$vm = $_
	$Datastores = $vm | Get-Datastore
	$Count = ($Datastores | Measure-Object).Count
	if ($Count -ge 2)
	{
		foreach ($ds in $Datastores) {
			$Report = "" | Select-Object -Property VmName, Datastore, Cluster
			$Report.VmName = $vm.Name
			$Report.Datastore = $ds.Name
			$Report.Cluster = ($vm | Get-Cluster).Name
			$Report
		}
	}
}
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I even found a bug in the previous script. If you have two VMs with the same name in two different clusters, with both VMs having only one datastore, the previous script will show these VMs. The new script does not.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 May 2010 21:29:35 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Find-count-VMs-with-2-or-more-VMDKs-on-different-Datastores/m-p/2557525#M86767</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2010-05-07T21:29:35Z</dc:date>
    </item>
  </channel>
</rss>

