使用Get-Disk cmdlet 时出错
Windows版本:Microsoft Windows Server 2008 R2 SP1 64b
Windows 2008 R2 powershell术语"Get-Disk"未被识别为cmdlet的名称。我有Powershell 的版本3
PS C:\Windows\system32>获取磁盘
Get-Disk : The term 'Get-Disk' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Disk
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-Disk:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\system32>$PSVersionTable`
Name Value
---- -----
WSManStackVersion 3.0
PSCompatibleVersions {1.0, 2.0, 3.0}
SerializationVersion 1.1.0.1
BuildVersion 6.2.9200.16398
PSVersion 3.0
CLRVersion 4.0.30319.1
PSRemotingProtocolVersion 2.2
[只需将注释组合成一个答案并添加一点]
我还想在Azure VM Server 2008 R2上使用Get-Disk
命令,我安装了PowerShell 3.0,但Get-Disk
仍然不可用,然后在谷歌上搜索到此页面。
从这个Scripting Guy博客链接中,它提到
注意:适用于Windows 7的Windows PowerShell 3.0版本没有此时包含存储模块,因此Windows 8或WindowsServer 2012是必需的。
因此,如果您希望在Windows Server 2008 R2上使用Get-Disk
,则不能。
同一个ScriptingGuy链接还提供了可以使用的相关DiskPart命令。
From an elevated shell:
DiskPart.exe
List disk
Select disk 1—disk 1 being the USB drive
Clean
Create partition primary
Select partition 1—partition 1 being the new partition
Active
Format FS=NTFS
根据您的使用情况,请注意,您也可以在不使用cmdlet的情况下,使用Win32_Volume类在powershell中获取磁盘上的信息。例如,您可以执行以下操作来更改驱动器号:
$drive = gwmi win32_volume -Filter "DriveLetter = 'F:'"
$drive.DriveLetter = "D:"
$drive.Put()