VMware Cloud Community
asingh1711
Contributor
Contributor
Jump to solution

Diskpart.exe command not working using powercli

I am trying to extend windows hard drive using diskpart utility via powercli but it hangs on 2nd command shown below.

1) Invoke-VMScript -VM $vmname -ScriptText "ECHO RESCAN > c:\DiskPart.txt && ECHO SELECT Volume C >> c:\DiskPart.txt && ECHO EXTEND >> c:\DiskPart.txt && ECHO EXIT >> c:\DiskPart.txt" -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword

2) Invoke-VMScript -VM $vmname -ScriptText "DiskPart.exe /s c:\DiskPart.txt " -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword

Is there any workaround for it or any other utility I can use to extend hard drive using power cli.

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you run the commands locally in the Guest OS with the same account as the one you use for the Invoke-VMScript cmdlet?


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You will have to provide a minimum of background information.
What type of Guest OS is running in that VM?

Did you try running the commands on the station interactively?


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

Reply
0 Kudos
asingh1711
Contributor
Contributor
Jump to solution

I have Windows 10 RS5 with PowerShell version 5.0. I am using Windows PowerShell ISE and invoking below 2 commands to increase hard disk size at VM level followed by disk expansion at OS level.

Script worked well for VMware part but diskpart.exe hangs for indefinite time.

Get-VM $vmname | Get-HardDisk | Where-Object {$_.Name -eq "Hard Disk 1"} | Set-HardDisk -CapacityGB $NewCapacityGB -Confirm:$false

Invoke-VMScript -VM $vmname -ScriptText "ECHO RESCAN > c:\DiskPart.txt && ECHO SELECT Volume C >> c:\DiskPart.txt && ECHO EXTEND >> c:\DiskPart.txt && ECHO EXIT >> c:\DiskPart.txt" -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword

Write-Host "script passed"

Invoke-VMScript -VM $vmname -ScriptText "DiskPart.exe /s c:\Users\oemqa\DiskPart.txt " -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword  ---------This line hang

Write-Host "script passed1"

However when I open powershell ISE on target VM , I am able to execute diskpart.exe command successfully.

Let me know if you need any more information.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you run the commands locally in the Guest OS with the same account as the one you use for the Invoke-VMScript cmdlet?


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

Reply
0 Kudos
asingh1711
Contributor
Contributor
Jump to solution

Yes, I am using same account.

This is not related to permission issue.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you run the 2 lines from a CMD prompt inside the Guest OS, does it work?
What is the output saying?

Do you get a prompt somewhere?


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

Reply
0 Kudos
asingh1711
Contributor
Contributor
Jump to solution

It works using command prompt inside the Guest OS.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then I'm out of ideas I'm afraid.


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

Reply
0 Kudos
asingh1711
Contributor
Contributor
Jump to solution

I think you referred below post in past but that doesn't helped me either.

VMware PowerCLI Forum - VMware {code}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, that would indicate an issue with UAC, which you obviously don't have.


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

SubhashMR
Contributor
Contributor
Jump to solution

Invoke-VMScript didn't worked for me due to VMware tool not running with current version, So I used Invoke-Command and succeeded.

Invoke-VMScript -VM $vmname -ScriptText "ECHO RESCAN > C:\DiskPart.txt && ECHO SELECT Volume C >> C:\DiskPart.txt && ECHO EXTEND >> C:\DiskPart.txt && ECHO EXIT >> C:\DiskPart.txt && DiskPart.exe /s C:\DiskPart.txt && DEL C:\DiskPart.txt /Q" -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword

$VM = "VM Name"

# Enter Guest OS Administrator Credential or elevated account

$compCred = Get-Credential

Invoke-Command -ComputerName $vm -Credential $compCred -ScriptBlock {"rescan","select volume C","extend" | diskpart}

Reply
0 Kudos