Windows 2008 R2 powershell 术语“Get-Disk”未被识别为 cmdlet 的名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14838967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:16:05  来源:igfitidea点击:

Windows 2008 R2 powershell The term 'Get-Disk' is not recognized as the name of a cmdlet

windowspowershell

提问by Sahen Gala

I am getting an error when using Get-Disk cmdlet

使用 Get-Disk cmdlet 时出现错误

Windows version: Microsoft Windows Server 2008 R2 SP1 64b

Windows 版本:Microsoft Windows Server 2008 R2 SP1 64b

Windows 2008 R2 powershell The term 'Get-Disk' is not recognized as the name of a cmdlet. I have version 3 of Powershell

Windows 2008 R2 powershell 术语“Get-Disk”未被识别为 cmdlet 的名称。我有 Powershell 的第 3 版

PS C:\Windows\system32> Get-Disk

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`

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

回答by Paul Rowland

[Just combining the comments into an answer and added a bit]

[只是将评论合并为答案并添加了一点]

I also was looking to use the Get-Diskcommand on an Azure VM Server 2008 R2, I installed PowerShell 3.0 and Get-Diskwas still not available, and then googled to this page.

我还希望Get-Disk在 Azure VM Server 2008 R2 上使用该命令,但我安装了 PowerShell 3.0Get-Disk但仍然不可用,然后在 google 上搜索到此页面。

From this Scripting Guy blog linkit mentions that

从这个脚本专家博客链接它提到

Note The version of Windows PowerShell 3.0 for Windows 7 does not contain the Storage module at this time, so Windows 8 or Windows Server 2012 is a requirement.

注意 Windows 7 的 Windows PowerShell 3.0 版本目前不包含存储模块,因此需要 Windows 8 或 Windows Server 2012。

So if your looking to use Get-Diskon Windows Server 2008 R2, you cant.

因此,如果您希望Get-Disk在 Windows Server 2008 R2 上使用,则不能。

The same Scripting Guy link also provides the relevant DiskPart commands that can be used instead.

相同的 Scripting Guy 链接还提供了可以替代使用的相关 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

回答by Vitorrio Brooks

Depending on your use case, note that you can also get information on the disk in powershell without using a cmdlet, using the Win32_Volume classFor example, you could do the following to change the drive letter:

请注意,根据您的用例,您还可以在不使用 cmdlet 的情况下,使用Win32_Volume 类在 powershell 中获取有关磁盘的信息。例如,您可以执行以下操作来更改驱动器号:

$drive = gwmi win32_volume -Filter "DriveLetter = 'F:'"
$drive.DriveLetter = "D:"
$drive.Put()