SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

powerclirdmvms

Script: PowerCLI: VMs with RDM disks

This is a remake of a script found on http://www.virtu-al.net/2008/12/23/list-vms-with-rdm/ with the following changes:

  • Added RDMs in virtualmode
  • Added csv export
  • Added the vmhost in the output
  • Made some code readability changes
#Script Source: http://www.virtu-al.net/2008/12/23/list-vms-with-rdm/
#Connect-VIServer MYVISERVER
 
$timestamp = Get-Date -format "yyyyMMdd-HH.mm"
# $csvFile = Read-Host "Enter csv file"
$csvfile = "D:\sjoerd\$timestamp-rdmvms.csv"
 
$report = @()
$vms = Get-VM | Get-View
foreach($vm in $vms){
   foreach($dev in $vm.Config.Hardware.Device){   
      if(($dev.gettype()).Name -eq "VirtualDisk"){
         if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode")){
         #if($dev.Backing.CompatibilityMode -eq "physicalMode"){
		 $row = "" | select VMName, Host, HDDeviceName, HDFileName, Mode
		 $row.VMName = $vm.Name
		 $getvm = Get-VM $row.VMName
		 $row.Host = $getvm.VMHost
		 $row.HDDeviceName = $dev.Backing.DeviceName
		 $row.HDFileName = $dev.Backing.FileName
		 $row.Mode = $dev.Backing.CompatibilityMode
		 $report += $row
		 }   
	  } 
   }
}
$report | export-csv -NoTypeInformation $csvfile
You could leave a comment if you were logged in.
powerclirdmvms.txt · Last modified: 2021/09/24 00:25 (external edit)