【发布时间】:2014-11-24 14:48:29
【问题描述】:
我正在尝试编写一个自动化脚本来为 VM 创建新分区。 当我尝试使用脚本运行 diskpart 时,它总是失败。
我正在使用 powershell 调用 diskpart。 我编写脚本 txt 文件并将其作为输入传递给 diskpart:
diskpart /s script.txt
这是我的 script.txt 的内容:
select disk 0
select partition 1
extend size=10240
create partition extended
create partition logical size=10240
assign letter=E
FORMAT FS = NTFS QUICK
create partition logical size=3072
assign letter=p
FORMAT FS = NTFS QUICK
create partition logical
assign letter=y
FORMAT FS = NTFS QUICK
它什么也没做,只是打印出所有命令,就像我输入的命令有语法错误一样。 我反复检查了我的脚本,应该是正确的,如果我在diskpart中一个一个运行它们就可以成功运行。
我什至在我的脚本中尝试了非常基本的命令,例如“list disk”,但它仍然具有相同的输出。 我认为这可能是一个非常基本的问题,但是我在网上搜索了一天仍然没有得到答案。 如果有人可以提供帮助或提供任何线索,将不胜感激。 谢谢。
'diskpart /s script.txt'的输出:
Microsoft DiskPart version 6.1.7600
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: AUTOHOSTNAME
Microsoft DiskPart version 6.1.7600
ACTIVE - Mark the selected partition as active.
ADD - Add a mirror to a simple volume.
ASSIGN - Assign a drive letter or mount point to the selected volume.
ATTRIBUTES - Manipulate volume or disk attributes.
ATTACH - Attaches a virtual disk file.
AUTOMOUNT - Enable and disable automatic mounting of basic volumes.
BREAK - Break a mirror set.
CLEAN - Clear the configuration information, or all information, off the
disk.
COMPACT - Attempts to reduce the physical size of the file.
CONVERT - Convert between different disk formats.
CREATE - Create a volume, partition or virtual disk.
DELETE - Delete an object.
DETAIL - Provide details about an object.
DETACH - Detaches a virtual disk file.
EXIT - Exit DiskPart.
EXTEND - Extend a volume.
EXPAND - Expands the maximum size available on a virtual disk.
FILESYSTEMS - Display current and supported file systems on the volume.
FORMAT - Format the volume or partition.
GPT - Assign attributes to the selected GPT partition.
HELP - Display a list of commands.
IMPORT - Import a disk group.
INACTIVE - Mark the selected partition as inactive.
LIST - Display a list of objects.
MERGE - Merges a child disk with its parents.
ONLINE - Online an object that is currently marked as offline.
OFFLINE - Offline an object that is currently marked as online.
RECOVER - Refreshes the state of all disks in the selected pack.
Attempts recovery on disks in the invalid pack, and
resynchronizes mirrored volumes and RAID5 volumes
that have stale plex or parity data.
REM - Does nothing. This is used to comment scripts.
REMOVE - Remove a drive letter or mount point assignment.
REPAIR - Repair a RAID-5 volume with a failed member.
RESCAN - Rescan the computer looking for disks and volumes.
RETAIN - Place a retained partition under a simple volume.
SAN - Display or set the SAN policy for the currently booted OS.
SELECT - Shift the focus to an object.
SETID - Change the partition type.
SHRINK - Reduce the size of the selected volume.
UNIQUEID - Displays or sets the GUID partition table (GPT) identifier or
master boot record (MBR) signature of a disk.
【问题讨论】:
标签: powershell