PowerCLI

 View Only
  • 1.  Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 01:53 PM

    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



  • 2.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 01:56 PM

    If you mean RDM disks, you can do

    $vm | Get-Harddisk -DiskType RawPhysical,RawVirtual 



  • 3.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 02:01 PM

    No, not an RDM.



  • 4.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 03:53 PM

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



  • 5.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 06:10 PM

    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.



  • 6.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 07, 2018 06:31 PM

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

    Are the VMware Tools installed?



  • 7.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 08, 2018 06:59 AM

    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.



  • 8.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 08, 2018 08:06 AM

    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.



  • 9.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 10, 2018 12:43 PM

    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



  • 10.  RE: Select a vm harddisk, partition style RAW? Format it

    Posted Apr 10, 2018 01:31 PM

    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: