VMware Cloud Community
Dave15
Contributor
Contributor

Select a vm harddisk, partition style RAW? Format it

The objective is to select a hard disk, check to see if it is RAW, if it is format it.

I can select a disk on a vm using

$vm | Get-Harddisk | where {$_.Name -eq "Hard disk 2"}

I'm having trouble finding out if the partition style is RAW.  I tried

$vm | Get-Harddisk | where {$_.Name -eq "Hard disk 2"} | Get-Disk | Select PartitionStyle

this fails.

Thanks,

Dave

0 Kudos
9 Replies
LucD
Leadership
Leadership

If you mean RDM disks, you can do

$vm | Get-Harddisk -DiskType RawPhysical,RawVirtual 


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

0 Kudos
Dave15
Contributor
Contributor

No, not an RDM.

0 Kudos
LucD
Leadership
Leadership

So you mean the guest OS partition(s) on the harddisk?


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

0 Kudos
Dave15
Contributor
Contributor

Correct, format the drive in the guest OS.  The guest OSes are W2K12R2 and W2K16.  The version of PowerShell is 4.0.  PowerCli is 6.5.4.

0 Kudos
LucD
Leadership
Leadership

You'll have to use Invoke-VMScript to run a script in the guest OS.

Are the VMware Tools installed?


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

0 Kudos
Dave15
Contributor
Contributor

Yes, VMTools is installed.  I'm curious to see where this goes.

I'm part of a team that builds servers for our company.  We use PowerShell scripts to help speed the process along as well as document what is done.  When we build SQL servers the process of adding drives and connecting them to specific SCSI Ids adds time, effort and confusion.  The script I'm working on would help the build process greatly.  (I used one of your other posts to help me get the Bus number and Unit number of the VM's hard disks - Thanks for that!)  The script is to the point to select the hard drive at a specific SCSI ID and format it.  That's why I originally asked about connecting PowerCLI's Get-Harddisk with PowerShell's Get-Disk.

The script is to be run after the server has joined the domain, from the server being built.  Because the server being built is on the domain, it can reach out and connect to the vCenter.  The PowerCLI modules are on the Test Server where I'm developing this script.  And the PSModulePath was updated.

0 Kudos
LucD
Leadership
Leadership

The problem is that there is no fool-proof method to link a VMDK to a guest OS partition, that would work equally well for a Windows as for a Linux guest OS.

There have been several posts that offer a solution, but they only seem to work under specific conditions.

The best way to proceed is to investigate your specific configuration, and determine a preferred method from there.

To name just a few methods:

  • mount the VMDK in question to a "helper" VM, and then do the guest OS partitioning from that "helper" VM.
  • add the VMDK one-by one, and then discover the new disk inside the guest OS (which will of course not work for the system/root partition).
  • if all the VMDK have a different capacity, you could use the disk size, to determine which VMDK is which disk in the guest OS.

And there are others.


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

0 Kudos
Dave15
Contributor
Contributor

LucD,

Thanks for your time and suggestions.  I value your input and use material you have previously posted as reference as well as your book.  You've given me more to think about than what I was originally considering. 

I kept searching and found a useful part of a script at Match VM and Windows harddisks using PowerShell | Arnim van Lieshout .

Get-WmiObject -Class Win32_DiskDrive -ComputerName $VmView.Name

will be used to connect the disk information provided by PowerCLI to the drive information provided by PowerShell from the OS through the SCSI IDs. 

Thanks again,

Dave

0 Kudos
LucD
Leadership
Leadership

Although that is a script we also have in our PowerCLI Reference book, it is not a fool-proof method that covers all possibilities.

But if it works for your specific situation, so much the better :smileygrin:


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

0 Kudos