Last active
November 12, 2015 08:27
-
-
Save desek/61a30dcc4c7e968a5f81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version should be 6.3* indicating Windows Server 2012 R2 | |
If ([System.Environment]::OSVersion.Version.ToString() -like "6.3*") | |
{ | |
# Windows Product Types. Script should only run on Server OS. | |
# 1: Workstation | |
# 2: Domain Controller | |
# 3: Server | |
If ((Get-WmiObject Win32_OperatingSystem -ErrorAction SilentlyContinue).ProductType -eq 3) | |
{ | |
$Disks = Get-PhysicalDisk -CanPool $true -ErrorAction SilentlyContinue | |
If (@($Disks).Count -gt 0) | |
{ | |
$StoragePoolName = "AzureDataDiskPool" | |
$StoragePool = Get-StoragePool -FriendlyName $StoragePoolName -ErrorAction SilentlyContinue | |
If (-not($StoragePool)) | |
{ | |
Try | |
{ | |
$StoragePool = New-StoragePool -StorageSubSystemFriendlyName *Spaces* -FriendlyName $StoragePoolName -PhysicalDisks $Disks | |
#$Columns = $Disks.Count | |
$Columns = 1 | |
$Interleave = 256kb | |
$VirtualDisk = New-VirtualDisk -StoragePoolFriendlyName $StoragePool.FriendlyName -FriendlyName "AzureDataDisk" -ResiliencySettingName Simple -Interleave $Interleave -ProvisioningType Fixed -UseMaximumSize -NumberOfColumns $Columns | |
Get-Disk -UniqueId $VirtualDisk.UniqueId | Initialize-Disk -Confirm:$false -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -AllocationUnitSize 64kb -Force -Confirm:$false | |
} | |
Catch | |
{ | |
Throw "Failed to add disk to new Storage Pool: $($_.Exception.Message)" | |
} | |
} | |
else | |
{ | |
Try | |
{ | |
Add-PhysicalDisk -StoragePool $StoragePool -PhysicalDisks $Disks | Out-Null | |
$StoragePool = Get-StoragePool -FriendlyName $StoragePool.FriendlyName | |
$VirtualDisk = Get-VirtualDisk -FriendlyName "AzureDataDisk" | |
$NewSize = ($VirtualDisk.Size)+(($StoragePool.Size)-($StoragePool.AllocatedSize)) | |
$VirtualDisk = Resize-VirtualDisk -InputObject $VirtualDisk -Size $NewSize -PassThru | |
Update-HostStorageCache | |
$Disk = Get-Disk -UniqueId $VirtualDisk.UniqueId | |
$Partition = $Disk | Get-Partition | Sort-Object -Property Size -Descending | Select-Object -First 1 | |
$NewPartitionSize = $Partition.Size + $Disk.LargestFreeExtent | |
Resize-Partition -InputObject $Partition -Size $NewPartitionSize -PassThru | |
} | |
Catch | |
{ | |
Throw "Failed to add disk to existing Storage Pool: $($_.Exception.Messsage)" | |
} | |
} | |
} | |
} | |
else | |
{ | |
Write-Output "Operatingsystem is not Server (ProductType = 3)." | |
} | |
} | |
else | |
{ | |
Write-Output "Operatingsystem is not of version 6.3* (Windows Server 2012 R2)." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment