search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Disk Operations in Windows Server 2008 R2 via PowerShell
Posted in Windows Powershell, Windows Server | 2 Comments | 6,189 views | 24/09/2013 10:47

There are some disk operations you can do in Windows Server 2008 R2 with PowerShell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Getting Disk Signature
Get-WmiObject Win32_DiskDrive | ft Name, Signature, Index
 
# Add Disk Signatures into Array
$Signatures = "650992792","650992689"
 
# Making Them Online
foreach ($Signature in $Signatures)
{
	$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
	$DiskID = $Disk.index
	$DiskPartScript = @"
select disk $DiskID
online disk noerr
"@
	$DiskPartScript | diskpart	
}
 
# Making Them Offline
foreach ($Signature in $Signatures)
{
	$Disk = Get-WmiObject Win32_DiskDrive | Where {$_.Signature -eq $Signature}
	$DiskID = $Disk.index
	$DiskPartScript = @"
select disk $DiskID
offline disk noerr
"@
	$DiskPartScript | diskpart	
}

Get-Disk is not available in Windows Server 2008 R2, so you should go with WMI.


Comments (2)

Kelley

October 29th, 2014
19:54:10

How can you get the signatures returned in the first command into the array automatically using powershell without manually entering each? I have some machines with 50 drives.


admin

October 31st, 2014
17:34:09

Hi Kelley,

You can use them like:

$Signatures = (Get-WmiObject Win32_DiskDrive).Signature

That will put all signatures into array.

Yusuf



Leave a Reply