Offline a Disk in Windows Server 2012r2 via WMI

Part of automating complex dependent systems is dealing with interconnection of those systems in a graceful manner. A project I am working on requires me to bring down a iSCSI server for updating and patching in a manner that will not result in corruption of data for the servers that rely on it.

In the virtual environment it is easy enough to power the dependent machines completely off, patch the back end server and then bring them back up again. This process breaks down when we are using physical front end servers, powering them off and bringing them back up via their management interfaces is an option but not an option that I can guarantee will work flawlessly.

My solution is to connect to the dependent physical machines using WMI shutdown the services that are using the iSCSi volume as storage and then offline the disks. When the iSCSi server has been restored to operational I can then online the disks, bring up the services and be back in business.

Here is the WMI code to Offline and Online a disk via powershell:

$MSFTDISK = Get-WmiObject -credential $Cred -computername $ServerName -Class MSFT_Disk -Namespace Root\Microsoft\Windows\Storage | where-object {$_.BusType -eq 9}

#BusType 9 = iscsi

$MSFTDISK.Offline() $MSFTDISK.Online()

It took a while to find it but it seems to work perfectly.

Jeremy Tirrell

Read more posts by this author.