英文:
How to do this in PowerShell?
问题
在PowerShell 5.1中如何执行以下操作:
create vdisk file="C:\Image.vhd" maximum=10000 type=expandable
attach vdisk
create partition primary
format fs=ntfs quick
rescan
assign letter=I
请注意,上述代码是在PowerShell 5.1中执行与您提供的脚本类似的操作。
英文:
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?
答案1
得分: 0
你需要安装 Hyper-V 及相关的 PowerShell 模块,然后可以创建磁盘:
New-VHD -Path "C:\Image.vhd" -Dynamic -SizeBytes 10485760000
挂载或附加磁盘,然后初始化它(假设只有一个额外的磁盘,如果有多个磁盘,您需要使用 get-disk
获取编号):
Mount-VHD -Path "C:\Image.vhd"
Initialize-Disk -Number 1 -PartitionStyle GPT
然后创建分区,设置驱动器字母,并快速格式化为 NTFS:
New-Partition -DiskNumber 1 -DriveLetter I | Format-Volume -FileSystem NTFS -Quick
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论