如何在PowerShell中执行此操作?

huangapple go评论85阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年1月6日 12:33:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定