locked
Take a HDD offline/online? RRS feed

  • Question

  • How can I take a disk offline/online with powershell?

     

    IE in Disk Management (Win 7, Win Server 2008 SP2) you can right click on the info box to the left of the disk partitions line (typically says something like Disk 0) and select offline/online.

    Wednesday, February 2, 2011 5:26 PM

Answers

  • I found that the following works fine in powershell:

     

    "select disk 2", "offline disk" | diskpart

    and to put it back online:

    "select disk 2", "online disk" | diskpart

    • Marked as answer by Alan Zhu Friday, February 4, 2011 6:04 AM
    Wednesday, February 2, 2011 7:26 PM
  • So, without creating any temporary script files you can call diskpart like this:

    PS C:\> $command = @'
    >> select disk 0
    >> offline disk
    >> '@
    >>
    PS C:\> $command | diskpart
    
    Microsoft DiskPart version 6.1.7600
    Copyright (C) 1999-2008 Microsoft Corporation.
    
    DISKPART>
    Disk 0 is now the selected disk.
    
    DISKPART>
    DiskPart successfully offlined the selected disk.
    
    DISKPART> PS C:\>
    
    • Marked as answer by Alan Zhu Friday, February 4, 2011 6:04 AM
    Wednesday, February 2, 2011 6:46 PM

All replies

  • you can use diskpart to get it online, but i never heard of an offline switch, only a delete...

    http://technet.microsoft.com/en-us/library/cc732026%28WS.10%29.aspx

    Wednesday, February 2, 2011 6:31 PM
  • Diskpart has an offline switch. At least on Win7 it does.

     PS C:\> diskpart

    DISKPART> select disk 0

    Disk 0 is now the selected disk.

    DISKPART> offline disk

    DiskPart successfully offlined the selected disk.

    DISKPART> online disk

    DiskPart successfully onlined the selected disk.

    DISKPART>

    Wednesday, February 2, 2011 6:36 PM
  • So, without creating any temporary script files you can call diskpart like this:

    PS C:\> $command = @'
    >> select disk 0
    >> offline disk
    >> '@
    >>
    PS C:\> $command | diskpart
    
    Microsoft DiskPart version 6.1.7600
    Copyright (C) 1999-2008 Microsoft Corporation.
    
    DISKPART>
    Disk 0 is now the selected disk.
    
    DISKPART>
    DiskPart successfully offlined the selected disk.
    
    DISKPART> PS C:\>
    
    • Marked as answer by Alan Zhu Friday, February 4, 2011 6:04 AM
    Wednesday, February 2, 2011 6:46 PM
  • I found that the following works fine in powershell:

     

    "select disk 2", "offline disk" | diskpart

    and to put it back online:

    "select disk 2", "online disk" | diskpart

    • Marked as answer by Alan Zhu Friday, February 4, 2011 6:04 AM
    Wednesday, February 2, 2011 7:26 PM
  • Command line to set online disk:

    DISKPART > list disk
    select disk x
    online disk

    After running diskpart to take disk online, you can change policy disk:
    DISKPART> SAN

    SAN Policy: Offline Shared

    Change the policy using: SAN Policy=OnlineAll


    • Edited by ElanoBR Monday, December 18, 2017 8:36 PM
    Monday, December 18, 2017 8:35 PM
  • Hi,

    I have win 7 and try to bring hdd into online by what you said above.. But, in disk management tool there is no info box to click and go.. And no success.......

    So, what do you talk about? There passed so much time wasting!!!!.....

    Thursday, February 13, 2020 9:17 PM