FlexRaid: powershell script to set disks online/offline

FlexRaid‘s products (Raid-F and tRaid) are setting offline all disks used as DRU or PPU to prevent direct access and mistakes. Access are made through virtual disks created by FlexRaid. But if you have many disks and sometimes needs to access your physical disks, you will like this script to reset online all those disks…

Click to Read More

Create a file to store this powershell script (ex.: ManageDisks.ps1) :

[code language=”shell”]

Clear-Host
$action = Read-Host ‘Type "Off" to set disks offline or "On" to set them online’
Clear-Host
if ($action.ToLower() -eq ‘off’)
{
echo ‘Please Wait…’
$lines = Get-Content C:\OffLineDisks.txt
foreach ($line in $lines) {
if ($line.Trim())
{
$fields = $line -split ‘ : ‘
$disk = $fields[1] $command = ‘"select disk ‘ + $disk + ‘", "offline disk" | diskpart’
echo $command
invoke-expression $command
}
}
}
elseif ($action.ToLower() -eq ‘on’) {
echo ‘Please Wait…’
Get-Disk | ? isoffline | Format-List Number > C:\OffLineDisks.txt
$lines = Get-Content C:\OffLineDisks.txt
foreach ($line in $lines) {
if ($line.Trim()) {
$fields = $line -split ‘ : ‘
$disk = $fields[1] $command = ‘"select disk ‘ + $disk + ‘", "online disk", "detail disk" | diskpart | Where-Object {$_ -match ".*Volume.*Partition" } 2>&1’
echo $command
$output = invoke-expression $command
if ($output -eq $null) {
echo "No Volume on disk $disk"
} else {
$fields = $output.TrimStart(" Volume") -split ‘ ‘
$volume = $fields[0] $command = ‘"select volume ‘ + $volume + ‘", "assign" | diskpart’
echo $command
invoke-expression $command
}
}
}
}
else
{
$message = $action + ‘ is not a supported action’
echo $message
}

[/code]

Usage: run this script “As Administrator” and

Type  ‘On’ to set online all disks currently offline. This will:

  1. Create a file OffLineDisks.txt on the C:\ drive with the ID of the disks currently offline. I presume that all disk offline are used by FlexRaid!
  2. Bring online each of those disks.
  3. Assign a letter to the volumes on those disks. I presume that there is only one volume per DRU and none on the PPU.

Type ‘Off’ to set offline the disks listed in the file OffLineDisks.txt created previously.

My purpose was to scan and repair various physical disks as this was not working when trying to do so via the NZFS Virtual Drives…

Click to Read More

Doing a Chkdsk on the NZFS Virtual Drive, I got:

Chkdsk was executed in read/write mode.

Checking file system on #:
Volume label is #.

Stage 1: Examining basic file system structure …

# file records processed. File verification completed.

  # large file records processed.

  # bad file records processed.

Stage 2: Examining file name linkage …
The data written out is different from what is being read back
at offset 0x# for 0x# bytes.
An unspecified error occurred (696e647863686b2e 1324).

So, instead, I do it on Physical Drives once set back online. And instead of Chkdks, I am using the powershell command “Repair-Volume”. E.g.: on a disk assigned with letter X:

PS C:\> Repair-Volume X -Scan
ScanErrorsFoundNeedSpotFix

PS C:\> Repair-Volume X
ErrorsFixed

PS C:\> Repair-Volume X -Scan
NoErrorsFound

Loading


Categories:

Tags:


Comments

One response to “FlexRaid: powershell script to set disks online/offline”

  1. Valery Letroye Avatar

    And here is a script to assign a free letter to any volume not yet assigned

    $volumes = “list volume” | diskpart | Where {$_ -match “^s+(Volume d+)s{5}W.+Partition”} | Foreach {$matches[1]}
    foreach ($v in $volumes) {
    “select $v `r`nassign” | diskpart
    }

Leave a Reply

Your email address will not be published. Required fields are marked *