Skip to content

Instantly share code, notes, and snippets.

@NatMarchand
Last active July 19, 2019 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NatMarchand/0386765d377bc1f7408e86bff0582779 to your computer and use it in GitHub Desktop.
Save NatMarchand/0386765d377bc1f7408e86bff0582779 to your computer and use it in GitHub Desktop.
MountDataDisks
param($StorageAccount, $StorageKey)
Start-Sleep -Milliseconds 1
function Mount-DataDisks {
$disks = Get-Disk | Where-Object partitionstyle -eq 'raw' | Sort-Object number
$letters = 73..89 | ForEach-Object { [char]$_ }
$count = 0
$label = "datadisk"
foreach ($disk in $disks) {
$driveLetter = $letters[$count].ToString()
$disk |
Initialize-Disk -PartitionStyle MBR -PassThru |
New-Partition -UseMaximumSize -DriveLetter $driveLetter |
Format-Volume -FileSystem NTFS -NewFileSystemLabel "$label.$count" -Confirm:$false -Force |
Out-Null
$count++
}
}
function Create-AzureFileShare {
param($StorageAccount, $StorageKey, $ShareName)
try {
Invoke-StorageApi -Method PUT -Uri "https://$StorageAccount.file.core.windows.net/$($ShareName.ToLowerInvariant())?restype=share" -Headers @{"x-ms-version" = "2015-02-21"; "x-ms-date" = [System.DateTime]::UtcNow.ToString("R") } -StorageAccount $StorageAccount -StorageKey $StorageKey
}
catch {
if ($_.Exception.Response.StatusCode -ne "Conflict") {
throw
}
}
#$createOperation
}
function Invoke-StorageApi {
param (
[Microsoft.PowerShell.Commands.WebRequestMethod] $Method,
[System.Uri]$Uri,
[System.Collections.IDictionary]$Headers,
[string]$StorageAccount,
[string]$StorageKey)
$signature = "$($Method.ToString().ToUpperInvariant())`n`n`n`n"
$Headers.Keys | Where-Object { $_ -match "x-ms" } | Sort-Object -CaseSensitive | ForEach-Object { $signature += $_ + ":" + $Headers[$_] + "`n" }
$signature += "/$StorageAccount" + $Uri.AbsolutePath
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Convert]::FromBase64String($StorageKey)
$signature = [Convert]::ToBase64String($hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($signature)))
$Headers.Add("Authorization", "SharedKeyLite ${StorageAccount}:$signature")
return Invoke-WebRequest -UseBasicParsing -Method $Method -Uri $Uri -Headers $Headers
}
Mount-DataDisks
Create-AzureFileShare -StorageAccount $StorageAccount -StorageKey $StorageKey -ShareName "traefik"
Create-AzureFileShare -StorageAccount $StorageAccount -StorageKey $StorageKey -ShareName "openvpn"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment