-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm-storage.ps1
60 lines (57 loc) · 1.94 KB
/
confirm-storage.ps1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Ensure that a storage account exists in the specified resource group
Function Confirm-Storage-Account {
[CmdletBinding()]
Param(
[string]$ResourceGroupName,
[string]$Name
)
Begin
{
$Location = 'eastus'
}
Process
{
# Create resource group if it does not already exist
$ResourceGroup = Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
if ($null -eq $ResourceGroup)
{
New-AzResourceGroup -Name $ResourceGroupName -Location $Location
}
# Create storage account if it does not already exist
$StorageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue
if ($null -eq $StorageAccount)
{
$StorageParams = @{
ResourceGroupName = $ResourceGroupName
Name = $Name
Location = $Location
SkuName = 'Standard_LRS'
AccessTier = 'Cool'
}
$StorageAccount = New-AzStorageAccount @StorageParams -AllowBlobPublicAccess $true
}
return $StorageAccount
}
}
# Ensure that a storage container exists in the specified storage account context
Function Confirm-Storage-Container {
[CmdletBinding()]
Param(
[string]$Name,
[object]$Context
)
Process
{
$StorageContainer = Get-AzStorageContainer -Name $Name -Context $Context -ErrorAction SilentlyContinue
if ($null -eq $StorageContainer)
{
$StorageContainer = New-AzStorageContainer -Name $Name -Context $Context -Permission Blob
}
return $StorageContainer
}
}
# Authenticate Azure account and verify that resources exist
Connect-AzAccount
$StorageAccount = Confirm-Storage-Account -ResourceGroupName 'media-resource-group' -Name 'epistrophy'
Confirm-Storage-Container -Name 'cd-vault' -Context $StorageAccount.Context
Confirm-Storage-Container -Name 'cd-vault-classical' -Context $StorageAccount.Context