I am trying to write a powercli script that will give me hard disk information for my VMs; however, I am running into a problem when I try to match drive letters to the SCSI Id. When the SCSI controller is 0, the drive letters are matched correctly; however, when it is higher than 0, it will swap the drive letters.
Below is an example of the disk drives for a particular VM and corresponding SCSI Ids.
Drive Letter SCSI Id
My script gives me the correct output EXCEPT for the drives that have a SCSI controller higher than 0. For example:
SCSI 1:0 should be drive letter J: instead of T:
SCSI 2:0 should be drive letter K: instead of J:
SCSI 3:0 should be drive letter T: instead of K:
In this example I am using the Get-WmiObject cmdlet, so the disk information matches the drive letter. I also tried doing it without using the Get-WmiObject cmdlet and the disk information matches the SCSI_Id; however, I can't get it so everything matches including Drive letter and SCSI Id.
Any ideas on how to do this? Any suggestions will be appreciated!
Thanks for the response. I bought the book, and I just received it today. I was wondering... Is there a way to get the drive letter using the get-vmdiskmapping cmdlet? I tried to use the script in the book and it worked, but I can't figure out how to get the drive letter. Any help would be appreciated!
I haven't had much time to read it, but I can see it will be very useful! but to answer your questions, yes, I copied the script from the website. So, is it possible to get the drive letter using that script? because I don't seem to find a way to do it. Please let me know.
So is it even possible to do it? I haven't found a way to get the drive letters to match SCSI Ports higher than 0 (1:0, 2:0, 3:0). I have tried many things, but none of them seem to work, and I am starting to realize that there isn't a way to do it. Please let me know if you have any ideas.
FYI, a long while back I reached a dead-end trying to match Win32_LogicalDiskToPartition (Antecedent) with Win32_DiskDriveToDiskPartition (dependentDeviceID). They don't seem to match up (for joins), the AntecedentDeviceID will be 'PHYSICALDRIVE0' for the first disk on each virtual scsi controller. Scripts will report >=2 C: drives when you use multilpe virtual scsi controllers.
I'd love to see something that can reliably match disks on multilpe virtual controllers.
I found this script which uses WMI from within a machine, or can be used remotely (you'll need to enable remoting for those servers)
Seems to do exactly what you need.
It doesn't reference the vSphere PowerCli in any way.
I believe it is possible to "mashup" Get-DiskScsiLun (from http://rvdnieuwendijk.com/2012/05/29/powershell-function-to-get-disk-scsi-lun-number/) with the script by Arnim van Lieshout (from http://www.van-lieshout.com/2009/12/match-vm-and-windows-harddisks-using-powercli/) in order to achieve this. I have it working but we only have 1 scsi controller per system, and our logical drive : partition ratio is always 1:1 also so I don't know if it would work against all setups. The type of object returned contains information as so:
SCSIController : SCSI controller 0
DiskName : Hard disk 3
SCSI_Id : 0:4
DiskFile : [vc01_vfi01_vol01] serverA/serverA3_4-000001.vmdk
DiskSize : 2
WindowsDisk : Disk 2
WindowsDriveLetter : T:
Sure @Mike_Yazbeck, Funnily enough, my brother is just working on taking the code and porting it to a new version of the web front end we use to run PowerShell scripts, so he's been enjoying the complexity of it. I'll put the required bits together and improve the error handling and get back to you shortly.
Many thanks :smileygrin:
Although I do like both scripts from Robert and Arnim, I found that with Arnim's script, I ran into issues when specifying /format:csv which then led me to this fix:
Having said that, I still never got the logical disk number in windows to populate. Having said that I have seen various methods to populate everything but using WMI.
Personally im not a big fan of running WMIC using invoke script... I can understand why its used, but if someone has misconfigured servers in the environment, you dont want to have to retrospectively fix those servers, I would rather a script that worked out of the box which is why I lean towards Robert's script.
Plus it has the added bonus of populating the drive letter which I imagine most people would want :smileygrin:
Although his sample output looks good, its not entirely obvious which correlates to what :smileysilly:
Im looking forward to your juicy script.
Thanks for your support and your efforts :smileygrin:
Hi sastre :smileygrin:
Just wondered how you got on with your super script?
I managed to do a mashup of my own, but I find getting the controller number ineffective.
I dont see how there is a reliable way to get it using WMI. Using the registry never works as the scripts I have send rely upon getting a specific key that matches a certain value which doesnt exist. I have checked against multiple servers with the same issue