Home > Software engineering >  How to do this in PowerShell?
How to do this in PowerShell?

Time:01-07

I have a dps script that does this

create vdisk file="C:\Image.vhd" maximum=10000 type=expandable
attach vdisk
create partition primary
format fs=ntfs quick
rescan
assign letter=I

How can I do this in PS 5.1?

CodePudding user response:

You would have to install Hyper-V and the associated PowerShell Module and then you could create the disk:

New-VHD -Path "C:\Image.vhd" -Dynamic -SizeBytes 10485760000

Mount, or attach, the disk then initialize it (assuming there is only one extra disk, if there are more than one disk you'd need to get the number using get-disk).

Mount-VHD -Path "C:\Image.vhd"
Initialize-Disk -Number 1 -PartitionStyle GPT

Then create the partition, set the drive letter and quickly format with NTFS

New-Partition -DiskNumber 1 -DriveLetter I | Format-Volume -FileSystem NTFS -Quick
  • Related