eblank
Contributor
Contributor

Powercli script to match drive letter and SCSI Id correctly

Hi,

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

       C:                             0:0

        I:                              0:1

       P:                             0:2

       Z:                              0:4

       J:                              1:0

       K:                             2:0

       T:                              3:0

My script gives me the correct output EXCEPT for the drives that have a SCSI controller higher than 0. For example:

Output.JPG

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!

15 Replies
LucD
Leadership
Leadership

In our book we have a script that does exactly this.

The source of the scripts from the book is available via the thread PowerCLI Book Module

Look for the function Get-VMDiskMapping.


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

0 Kudos
eblank
Contributor
Contributor

LucD,

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!

Thanks,

Eugenio

0 Kudos
LucD
Leadership
Leadership

Thanks for buying the book, I hope you will enjoy it.

I assume you are referring to the script in Listin 7.4 ?

Did you get the listing from the website ?

I'm afraid we don't provide the drive letters in that script.


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

0 Kudos
eblank
Contributor
Contributor

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.

Thanks!

0 Kudos
LucD
Leadership
Leadership

No, I'm afraid we don't provide the drive letter in that script.


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

0 Kudos
eblank
Contributor
Contributor

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.

Thanks again,

Eugenio

0 Kudos
LucD
Leadership
Leadership

For now, I have no clue how this could be done.

Which doesn't mean it isn't possible of course :smileygrin:

I'll put it on my list of things to investigate.


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

0 Kudos
eblank
Contributor
Contributor

I will keep looking, and if I find a solution I will post it here... If you find a solution before I do please let me know. I appreciate your help!

Thanks,

Eugenio

0 Kudos
BenConrad
Expert
Expert

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.

Ben

0 Kudos
Spolson
Contributor
Contributor

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.

http://rvdnieuwendijk.com/2012/05/29/powershell-function-to-get-disk-scsi-lun-number/

It doesn't reference the vSphere PowerCli in any way.

Have fun!

Cheers,

Scott

0 Kudos
sastre
Enthusiast
Enthusiast

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:

0 Kudos
Mike_Yazbeck
Enthusiast
Enthusiast

Care to share your version? :smileygrin:

The ones I have seen are good, but they dont seem to provide the windows disk number.

0 Kudos
sastre
Enthusiast
Enthusiast

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.

Mike_Yazbeck
Enthusiast
Enthusiast

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:

command line - wmic error (invalid XSL format) in windows7 - Stack Overflow

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:

0 Kudos
Mike_Yazbeck
Enthusiast
Enthusiast

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

Cheers

0 Kudos