{"id":112,"date":"2010-06-29T09:56:26","date_gmt":"2010-06-29T16:56:26","guid":{"rendered":"http:\/\/joshua.frederici.net\/blog\/?p=112"},"modified":"2010-06-29T09:56:26","modified_gmt":"2010-06-29T16:56:26","slug":"vmware-determining-ownership-of-a-virtual-disk-using-powershell","status":"publish","type":"post","link":"https:\/\/joshua.frederici.net\/blog\/vmware-determining-ownership-of-a-virtual-disk-using-powershell\/","title":{"rendered":"VMware &#8211; Determining ownership of a virtual disk using PowerShell"},"content":{"rendered":"<p>So as you may have guessed, I work with VMware a bit in my employment. On top of that, I&#8217;ve tried to start using PowerShell to automate repetitive tasks that I run into. (In fact, one of the major points of the existence of this page is to give myself a location to store these findings in a place which I can find them later, and if someone else finds them useful, then great.)<\/p>\n<p>Anyway, the problem I ran into today was that I had a VM on a datastore whose name did not match a VM in my vCenter inventory. How could I tell if these files were in use by a legitimate VM or just wasting space? I could right-click and &#8216;Edit Settings&#8217; on hundreds of VM&#8217;s&#8230; or I could use Powershell.<\/p>\n<p>so I started off by connecting to the vCenter server and getting an inventory of VM&#8217;s:<\/p>\n<p><code><br \/>\nConnect-VIServer servername<br \/>\n$VM = Get-VM<br \/>\n<\/code><\/p>\n<p>Then I grabbed a list of disks which matched my criteria:<\/p>\n<p><code>$Disks = $VM | Get-HardDisk | Where {$_.FileName -like '*web*' }<\/code><\/p>\n<p>Then I did&#8230;<\/p>\n<p><code>$Disks | Get-Member<\/code> and saw that there are Name, FileName, and ParentID properties. By doing <code>$Disks | Select Name, FileName, ParentID<\/code>,\u00a0\u00a0I now have the parent Id of the VM.<\/p>\n<p>So how do I know which VM the parent ID field references?<\/p>\n<p><code>$VM | Where {$_.Id -like 'parent id from previous select'}<\/code><\/p>\n<p>&#8230; which returns &#8230;.<\/p>\n<p><code><br \/>\nName PowerState Num CPUs Memory (MB)<br \/>\n---- ---------- -------- -----------<br \/>\nWebSrv1 PoweredOn 4 4096<br \/>\n<\/code><\/p>\n<p>Is there an easier way to do this? Probably, and I already have a couple of ideas. If I can get them working and cleaned up, I&#8217;ll post them here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So as you may have guessed, I work with VMware a bit in my employment. On top of that, I&#8217;ve tried to start using PowerShell to automate repetitive tasks that I run into. (In fact, one of the major points of the existence of this page is to give myself a location to store these [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,6],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-tech-powershell","category-tech-virtualization"],"_links":{"self":[{"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":0,"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joshua.frederici.net\/blog\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}