【问题标题】:Windows 2008 R2 powershell The term 'Get-Disk' is not recognized as the name of a cmdletWindows 2008 R2 powershell 术语“Get-Disk”未被识别为 cmdlet 的名称
【发布时间】:2013-02-12 18:10:31
【问题描述】:

使用 Get-Disk cmdlet 时出现错误

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

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

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

【问题讨论】:

  • 这很奇怪。当你运行 Get-Command -Module Storage 时,你有什么收获吗?如果没有,请尝试Import-Module Storage,然后再尝试第一个。只是为了确定您是否缺少模块或自动加载不起作用
  • module-storage 仅适用于 windows 2012 不是吗?
  • 我不确定它是否仅在 2012 年可用。本来希望在 2008 R2 上使用它。我将 powershell 升级到 3.0,但它仍然无法正常工作。所以假设它仅在 2012(或 Windows 8)及更高版本上受支持。
  • kayasax 似乎是正确的:blogs.technet.com/b/heyscriptingguy/archive/2012/10/26/…good catch =)
  • 还尝试了 2 个命令,但“Get-Command -Module Storage”没有响应,而另一个我收到错误消息。 Import-Module : 未加载指定的模块“Storage”,因为在任何模块目录中都找不到有效的模块文件。

标签: windows powershell


【解决方案1】:

[只是将cmets组合成一个答案并添加了一点]

我还想在 Azure VM Server 2008 R2 上使用 Get-Disk 命令,我安装了 PowerShell 3.0 并且 Get-Disk 仍然不可用,然后用 Google 搜索到此页面。

从这个Scripting Guy blog link 中提到

注意 Windows 7 的 Windows PowerShell 3.0 版本不 此时包含存储模块,因此 Windows 8 或 Windows Server 2012 是一项要求。

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

相同的 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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 2021-06-24
      • 2020-06-12
      • 2019-10-12
      相关资源
      最近更新 更多