powershell script for expanding c drive in Vmware VM and extending the disk in same script

Can anyone help in extending the c drive:disk1 in vmware VM and extending the c drive in same script.
I am able to extend the disk via powercli with oneliner script but challenge is extending the c drive in windows without using diskpart diskmgmt.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Powershell 3.0 in Windows 8.0 and Windows 2012, has supported for re-size partition

Get-PartitionSupportedSize and Resize-Partition functions can be used.

What is your OS?
aspathakAuthor Commented:
Thanks Andy. I need to extend the c drive for multiple VMs on ESX.majority of these hosts are 2008 and I need a script for carrying on this task along with extending the disk
Andrew Hancock (VMware vExpert / EE MVE^2)VMware and Virtualization ConsultantCommented:
Personally, we would do it manually, and check all is okay, and make sure you have a full backup before you attempt this, as re-sizing often goes wrong in the OS. (not a snapshot!).

We would never attempt to write a powershell script to extend the disks, and OS partitions, that is asking for trouble, as so much can go wrong, and usually does manually, and then we only ever re-size a disk, by checking the existing resources, e.g. datastores, are not going to be low, e.g. less than 25-30% storage space.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I can only agree to that. I would not try to automate this action, at least not without including the backup - and that requires you to mix up outband and inband PowerShell code, making ti more complex than it is worth it.
Doing this in an automated fashion is a bit scary but if you are doing this in a test or have do other choice you could write a batch file that would call diskpart -> list volume -> select volume x - >extend...

I would then create a computer group policy to run the script since a computer policy would run the script as the local system account

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.