5
votes

I am getting an error when using Get-Disk cmdlet

Windows version: 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

PS C:\Windows\system32> Get-Disk

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
2
That's weird. Do you get anything when you run Get-Command -Module Storage ? If not, try Import-Module Storage, and then the first one again. Just to identify if you're missing the module or auto-loading is not workingFrode F.
module-storage is only available for windows 2012 isnt it ?Loïc MICHEL
I am not sure if it was only available in 2012. Would have liked to use it on 2008 R2. I upgraded powershell to 3.0 but it still does not work. So assuming it is only supported on 2012 (or Windows 8) and above.Sahen Gala
kayasax seems to be correct: blogs.technet.com/b/heyscriptingguy/archive/2012/10/26/… good catch =)Frode F.
Also tried the 2 commands but no response for "Get-Command -Module Storage" and for the other I get an error back. Import-Module : The specified module 'Storage' was not loaded because no valid module file was found in any module directory.Sahen Gala

2 Answers

7
votes

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

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

From this Scripting Guy blog link it 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.

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

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

From an elevated shell:

    DiskPart.exe
    List disk
    Select disk 1—disk 1 being the USB drive
    Clean
    Create partition primary
    Select partition 1partition 1 being the new partition
    Active
    Format FS=NTFS
2
votes

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 class For example, you could do the following to change the drive letter:

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