none
Multiple disks online using PowerShell

    Question

  • Hello !

    This is a test scenario where I've tested the script on win 2k8r2 and win2k12 r2 , with three HDD C: D: and E each 50GB.

    i am working on a script that would detect the offline disks and make them online..In order to test that I started to work with making single disk offline ie D drive, using the below script.

    For single disk offline the script had no issues.

    #Check for offline disks on server.
    
    $offlinedisk = "list disk" | diskpart | where {$_ -match "offline"}
    
    #If offline disk(s) exist
    if($offlinedisk)
    
    {
    
        #for all offline disk(s) found on the server
        foreach($offdisk in $offlinedisk)
        {
        
        $offdiskS = $offdisk.Substring(2,6)
    
    #Creating command parameters for selecting disk, making disk online and setting off the read-only flag.
    $OnlineDisk = @"
    select $offdiskS
    online disk
    attributes disk clear readonly
    "@
        #Sending parameters to diskpart
        $OnlineDisk | diskpart
        
        }
        #If auto-fix failed throw the alert.
        if(($offlinedisk = "list disk" | diskpart | where {$_ -match "offline"}))
        {
    
            $offlinedisk
    
        }
    
    }
    #If no offline disk(s) exist.
    else
    {
        #All disk(s) are online.
        Write-Host "All disk(s) are online!"
    
    }

    While making 2 disks online, randomly one of the disk is going into read-only mode even when the read-only flag is cleared.

    from the command prompt the read-only flag shows as : No

    am i missing something very simple?

    Observed same behavior on win 2k8r2 and win2k12 r2.

    Since we have servers which are on 2k8r2 , i preferred not to use the 'storage module'

    Regards,

    Venu


    Venu


    • Edited by VGSandz Monday, July 27, 2015 11:30 AM
    Monday, July 27, 2015 11:21 AM

Answers

  • This I snot a scripting issue.  Read the following and contact Microsoft support:
    https://support.microsoft.com/en-us/kb/840781


    \_(ツ)_/

    • Marked as answer by VGSandz Tuesday, July 28, 2015 5:19 AM
    Monday, July 27, 2015 1:16 PM
    Moderator
  • Thanks Jrv,

    I understood the issue now. I can't go for paid support on this.. :)

    However when i doubled the 'attributes disk clear readonly' it seems to be stable enough for my testing to continue.

    #Creating command parameters for selecting disk, making disk online and setting off the read-only flag.
    $OnlineDisk = @"
    select $offdiskS
    attributes disk clear readonly
    online disk
    attributes disk clear readonly
    "@
        #Sending parameters to diskpart
        $OnlineDisk | diskpart

    Regards

    Venu


    Venu

    • Marked as answer by VGSandz Tuesday, July 28, 2015 5:19 AM
    Tuesday, July 28, 2015 5:18 AM

All replies

  • This I snot a scripting issue.  Read the following and contact Microsoft support:
    https://support.microsoft.com/en-us/kb/840781


    \_(ツ)_/

    • Marked as answer by VGSandz Tuesday, July 28, 2015 5:19 AM
    Monday, July 27, 2015 1:16 PM
    Moderator
  • Thanks Jrv,

    I understood the issue now. I can't go for paid support on this.. :)

    However when i doubled the 'attributes disk clear readonly' it seems to be stable enough for my testing to continue.

    #Creating command parameters for selecting disk, making disk online and setting off the read-only flag.
    $OnlineDisk = @"
    select $offdiskS
    attributes disk clear readonly
    online disk
    attributes disk clear readonly
    "@
        #Sending parameters to diskpart
        $OnlineDisk | diskpart

    Regards

    Venu


    Venu

    • Marked as answer by VGSandz Tuesday, July 28, 2015 5:19 AM
    Tuesday, July 28, 2015 5:18 AM
  • Hi there, your script works great, just wondering if you have any insight on this issue. We have 10 disks that are offline, your script brings 8 of the 10 drives online with no issues.

    The last 2 drives do not come online, however I can go into disk management and bring online with out any issue.

    Any ideas?

    Wednesday, November 18, 2015 7:03 PM