Automating Add disk to server 2012r2 utilizing powershell script VM orchestrator

This topic contains 1 reply, has 2 voices, and was last updated by  Pradeep Arora 3 months ago.

  • Author
  • #93837


    I built a power shell script to automate adding disk to server 2012 r2 via VMro and VMra. The script runs and correctly adds the disk. The script also runs commands to search for new disk, initialize, assign drive letter and format with NTFS. The issue I am having is when I log onto the server. I can see the disk was added, but not formated. UAC and disk format opens up and ask If I want to allow format to run and the I have to click on format for it to complete. How do I get around this? Below is the script I am running. Note we are running this under a domain admin account.

    [int] $addGb,

    ### import VMware PowerCLI module
    Get-Module -Name VMware* -ListAvailable | Import-Module

    ### Connect to the vCenter instance
    Connect-VIServer -User $username -Password $password
    Connect-VIServer -User $username -Password $password

    ### Retrieve server object
    $server = Get-VM -Name $servername

    ### Add new drive
    $server | New-HardDisk -CapacityGB $addGb

    #region –> Call an invoke to extend the OS with loop (no reboot required)
    Invoke-Command -ComputerName $server -ScriptBlock {
    $VolumeNumber = (Get-Disk | where {$_.partitionstyle -eq 'raw'}).Number
    Get-Disk -Number $VolumeNumber | Initialize-Disk -PartitionStyle GPT
    New-Partition -DiskNumber $VolumeNumber -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -Confirm:$false -Force
    "Guest OS Disk successfully Added and partioned"

  • #93879

    Pradeep Arora

    You are missing ' | ' between commands Initialize-Disk and New-Partition
    Probably New-Partition is not getting executed

You must be logged in to reply to this topic.