Posted in
Windows Powershell,
Windows Server |
2 Comments | 7,681 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
} |
# 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.