@@ -8,13 +8,21 @@ function Get-AzureRmStorageAccount
8
8
[string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] [alias (" StorageAccountName" )] $Name )
9
9
BEGIN {
10
10
$context = Get-Context
11
- $client = Get-StorageClient $context
11
+ $client = Get-StorageClient $context
12
+ $version = $client.GetType ().Assembly.GetName().Version
12
13
}
13
14
PROCESS {
14
- $getTask = $client.StorageAccounts.GetPropertiesAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
15
- $sa = $getTask.Result
16
- $account = Get-StorageAccount $ResourceGroupName $Name
17
- Write-Output $account
15
+ if ($version.Major -gt 3 )
16
+ {
17
+ $getTask = $client.StorageAccounts.GetPropertiesWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
18
+ }
19
+ else
20
+ {
21
+ $getTask = $client.StorageAccounts.GetPropertiesAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
22
+ }
23
+ $sa = $getTask.Result
24
+ $account = Get-StorageAccount $ResourceGroupName $Name
25
+ Write-Output $account
18
26
}
19
27
END {}
20
28
@@ -26,11 +34,12 @@ function New-AzureRmStorageAccount
26
34
param (
27
35
[string ] [Parameter (Position = 0 , ValueFromPipelineByPropertyName = $true )] $ResourceGroupName ,
28
36
[string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )][alias (" StorageAccountName" )] $Name ,
29
- [string ] [Parameter (Position = 2 , ValueFromPipelineByPropertyName = $true )] $Location ,
37
+ [string ] [Parameter (Position = 2 , ValueFromPipelineByPropertyName = $true )] $Location ,
30
38
[string ] [Parameter (Position = 3 , ValueFromPipelineByPropertyName = $true )] $typeString )
31
39
BEGIN {
32
40
$context = Get-Context
33
- $client = Get-StorageClient $context
41
+ $client = Get-StorageClient $context
42
+ $version = $client.GetType ().Assembly.GetName().Version
34
43
}
35
44
PROCESS {
36
45
$createParms = New-Object - Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
@@ -41,12 +50,19 @@ function New-AzureRmStorageAccount
41
50
else
42
51
{
43
52
$Type = Parse- Type $typeString
44
- }
53
+ }
45
54
46
- $createParms.AccountType = $Type
47
- $createParms.Location = $Location
48
- $getTask = $client.StorageAccounts.CreateAsync ($ResourceGroupName , $name , $createParms , [System.Threading.CancellationToken ]::None)
49
- $sa = $getTask.Result
55
+ $createParms.AccountType = $Type
56
+ $createParms.Location = $Location
57
+ if ($version.Major -gt 3 )
58
+ {
59
+ $getTask = $client.StorageAccounts.CreateWithHttpMessagesAsync ($ResourceGroupName , $name , $createParms , $null , [System.Threading.CancellationToken ]::None)
60
+ }
61
+ else
62
+ {
63
+ $getTask = $client.StorageAccounts.CreateAsync ($ResourceGroupName , $name , $createParms , [System.Threading.CancellationToken ]::None)
64
+ }
65
+ $sa = $getTask.Result
50
66
}
51
67
END {}
52
68
@@ -63,11 +79,20 @@ function Set-AzureRmStorageAccount
63
79
BEGIN {
64
80
$context = Get-Context
65
81
$client = Get-StorageClient $context
82
+ $version = $client.GetType ().Assembly.GetName().Version
66
83
}
67
84
PROCESS {
68
85
$createParms = New-Object - Type Microsoft.Azure.Management.Storage.Models.StorageAccountUpdateParameters
69
86
$createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType ]::StandardLRS
70
- $getTask = $client.StorageAccounts.UpdateAsync ($ResourceGroupName , $Name , $createParms , [System.Threading.CancellationToken ]::None)
87
+
88
+ if ($version.Major -gt 3 )
89
+ {
90
+ $getTask = $client.StorageAccounts.UpdateWithHttpMessagesAsync ($ResourceGroupName , $Name , $createParms , $null , [System.Threading.CancellationToken ]::None)
91
+ }
92
+ else
93
+ {
94
+ $getTask = $client.StorageAccounts.UpdateAsync ($ResourceGroupName , $Name , $createParms , [System.Threading.CancellationToken ]::None)
95
+ }
71
96
$sa = $getTask.Result
72
97
}
73
98
END {}
@@ -82,11 +107,21 @@ function Get-AzureRmStorageAccountKey
82
107
[string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] [alias (" StorageAccountName" )] $Name )
83
108
BEGIN {
84
109
$context = Get-Context
85
- $client = Get-StorageClient $context
110
+ $client = Get-StorageClient $context
111
+ $version = $client.GetType ().Assembly.GetName().Version
86
112
}
87
- PROCESS {
88
- $getTask = $client.StorageAccounts.ListKeysAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
89
- Write-Output $getTask.Result.StorageAccountKeys
113
+ PROCESS {
114
+ if ($version.Major -gt 3 )
115
+ {
116
+ $getTask = $client.StorageAccounts.ListKeysWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
117
+ $result = $getTask.GetAwaiter ().GetResult()
118
+ Write-Output $result.Body
119
+ }
120
+ else
121
+ {
122
+ $getTask = $client.StorageAccounts.ListKeysAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
123
+ Write-Output $getTask.Result.StorageAccountKeys
124
+ }
90
125
}
91
126
END {}
92
127
}
@@ -100,11 +135,19 @@ function Remove-AzureRmStorageAccount
100
135
[string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] [alias (" StorageAccountName" )] $Name )
101
136
BEGIN {
102
137
$context = Get-Context
103
- $client = Get-StorageClient $context
138
+ $client = Get-StorageClient $context
139
+ $version = $client.GetType ().Assembly.GetName().Version
104
140
}
105
141
PROCESS {
106
- $getTask = $client.StorageAccounts.DeleteAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
107
- $sa = $getTask.Result
142
+ if ($version.Major -gt 3 )
143
+ {
144
+ $getTask = $client.StorageAccounts.DeleteWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
145
+ }
146
+ else
147
+ {
148
+ $getTask = $client.StorageAccounts.DeleteAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
149
+ }
150
+ $sa = $getTask.Result
108
151
}
109
152
END {}
110
153
@@ -114,12 +157,12 @@ function Get-Context
114
157
{
115
158
[Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ]$context = $null
116
159
$profile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider ]::Instance.Profile
117
- if ($profile -ne $null )
118
- {
119
- $context = $profile.Context
120
- }
160
+ if ($profile -ne $null )
161
+ {
162
+ $context = $profile.Context
163
+ }
121
164
122
- return $context
165
+ return $context
123
166
}
124
167
125
168
function Parse-Type
@@ -133,20 +176,29 @@ function Get-Context
133
176
function Get-StorageClient
134
177
{
135
178
param ([Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ] $context )
136
- $factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession ]::ClientFactory
137
- [System.Type []]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]
138
- $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateClient" , $types )
139
- $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Storage.StorageManagementClient ])
140
- $arguments = $context , [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]::ResourceManager
141
- $client = $closedMethod.Invoke ($factory , $arguments )
142
- return $client
179
+ $factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession ]::ClientFactory
180
+ [System.Type []]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]
181
+ $storageClient = [Microsoft.Azure.Management.Storage.StorageManagementClient ]
182
+ $storageVersion = [System.Reflection.Assembly ]::GetAssembly($storageClient ).GetName().Version
183
+ if ($storageVersion.Major -gt 3 )
184
+ {
185
+ $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateArmClient" , $types )
186
+ }
187
+ else
188
+ {
189
+ $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateClient" , $types )
190
+ }
191
+ $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Storage.StorageManagementClient ])
192
+ $arguments = $context , [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]::ResourceManager
193
+ $client = $closedMethod.Invoke ($factory , $arguments )
194
+ return $client
143
195
}
144
196
145
197
function Get-StorageAccount {
146
198
param ([string ] $resourceGroupName , [string ] $name )
147
- $endpoints = New-Object PSObject - Property @ {" Blob" = " https://$name .blob.core.windows.net/" }
148
- $sa = New-Object PSObject - Property @ {" Name" = $name ; " ResourceGroupName" = $resourceGroupName ;
149
- " PrimaryEndpoints" = $endpoints
150
- }
199
+ $endpoints = New-Object PSObject - Property @ {" Blob" = " https://$name .blob.core.windows.net/" }
200
+ $sa = New-Object PSObject - Property @ {" Name" = $name ; " ResourceGroupName" = $resourceGroupName ;
201
+ " PrimaryEndpoints" = $endpoints
202
+ }
151
203
return $sa
152
- }
204
+ }
0 commit comments