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.
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
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
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.
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
Yes, I am using same account.
This is not related to permission issue.
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
It works using command prompt inside the Guest OS.
Then I'm out of ideas I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think you referred below post in past but that doesn't helped me either.
No, that would indicate an issue with UAC, which you obviously don't have.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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}