@@ -9,17 +9,9 @@ function Get-AzureRmStorageAccount
99 BEGIN {
1010 $context = Get-Context
1111 $client = Get-StorageClient $context
12- $version = $client.GetType ().Assembly.GetName().Version
1312 }
1413 PROCESS {
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- }
14+ $getTask = $client.StorageAccounts.GetPropertiesWithHttpMessagesAsync ($ResourceGroupName , $name )
2315 $sa = $getTask.Result
2416
2517 if ($sa -ne $null )
@@ -45,46 +37,23 @@ function New-AzureRmStorageAccount
4537 BEGIN {
4638 $context = Get-Context
4739 $client = Get-StorageClient $context
48- $version = $client.GetType ().Assembly.GetName().Version
4940 }
5041 PROCESS {
51- $createParms = New-Object - Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
52- if ($version.Major -lt 5 )
53- {
54- if ($typeString -eq $null )
42+ $createParms = New-Object - Type Microsoft.Azure.Management.Storage.Version2017_10_01.Models.StorageAccountCreateParameters
43+ if ([string ]::IsNullOrEmpty($typeString ))
5544 {
56- $Type = [Microsoft.Azure.Management.Storage.Models.AccountType ]::StandardLRS
45+ $Type = [Microsoft.Azure.Management.Storage.Version2017 _10_01. Models.SkuName ]::StandardLRS
5746 }
5847 else
5948 {
60- $Type = Parse- Type $typeString $version .Major
49+ $Type = Parse- Type $typeString
6150 }
6251
63- $createParms.AccountType = $Type
64- }
65- else
66- {
67- if ($typeString -eq $null )
68- {
69- $Type = [Microsoft.Azure.Management.Storage.Models.SkuName ]::StandardLRS
70- }
71- else
72- {
73- $Type = Parse- Type $typeString $version.Major
74- }
75-
76- $createParms.Sku = New-Object - Type Microsoft.Azure.Management.Storage.Models.Sku $Type
77- }
52+ $createParms.Sku = New-Object - Type Microsoft.Azure.Management.Storage.Version2017_10_01.Models.Sku $Type
7853 $createParms.Location = $Location
79- if ($version.Major -gt 3 )
80- {
81- $getTask = $client.StorageAccounts.CreateWithHttpMessagesAsync ($ResourceGroupName , $name , $createParms , $null , [System.Threading.CancellationToken ]::None)
82- }
83- else
84- {
85- $getTask = $client.StorageAccounts.CreateAsync ($ResourceGroupName , $name , $createParms , [System.Threading.CancellationToken ]::None)
86- }
87- $sa = $getTask.Result
54+ $getTask = $client.StorageAccounts.CreateWithHttpMessagesAsync ($ResourceGroupName , $name , $createParms )
55+ $sa = $getTask.Result.Body
56+ Write-Output $sa
8857 }
8958 END {}
9059
@@ -105,23 +74,19 @@ function Set-AzureRmStorageAccount
10574 $version = $client.GetType ().Assembly.GetName().Version
10675 }
10776 PROCESS {
108- $createParms = New-Object - Type Microsoft.Azure.Management.Storage.Models.StorageAccountUpdateParameters
109- $createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType ]::StandardLRS
110-
111- if ($version.Major -gt 3 )
112- {
113- $getTask = $client.StorageAccounts.UpdateWithHttpMessagesAsync ($ResourceGroupName , $Name , $createParms , $null , [System.Threading.CancellationToken ]::None)
114- }
115- else
116- {
117- $getTask = $client.StorageAccounts.UpdateAsync ($ResourceGroupName , $Name , $createParms , [System.Threading.CancellationToken ]::None)
77+ $createParms = New-Object - Type Microsoft.Azure.Management.Storage.Version2017_10_01.Models.StorageAccountUpdateParameters
78+ if ([string ]::IsNullOrEmpty($Type )) {
79+ $Type = [Microsoft.Azure.Management.Storage.Version2017 _10_01.Models.SkuName ]::StandardLRS
11880 }
119- $sa = $getTask.Result
81+ $sku = New-Object - Type Microsoft.Azure.Management.Storage.Version2017_10_01.Models.Sku - ArgumentList @ ([Microsoft.Azure.Management.Storage.Version2017 _10_01.Models.SkuName ]::$type )
82+ $createParms.Sku = $sku
83+ $getTask = $client.StorageAccounts.UpdateWithHttpMessagesAsync ($ResourceGroupName , $Name , $createParms )
84+ $sa = $getTask.Result.Body
85+ Write-Output $sa
12086 }
12187 END {}
12288}
12389
124-
12590function Get-AzureRmStorageAccountKey
12691{
12792 [CmdletBinding ()]
@@ -132,26 +97,10 @@ function Get-AzureRmStorageAccountKey
13297 BEGIN {
13398 $context = Get-Context
13499 $client = Get-StorageClient $context
135- $version = $client.GetType ().Assembly.GetName().Version
136100 }
137101 PROCESS {
138- if ($version.Major -gt 5 )
139- {
140- $getTask = $client.StorageAccounts.ListKeysWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
141- $result = $getTask.GetAwaiter ().GetResult()
142- Write-Output $result.Body.Keys
143- }
144- elseif ($version.Major -gt 3 )
145- {
146- $getTask = $client.StorageAccounts.ListKeysWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
147- $result = $getTask.GetAwaiter ().GetResult()
148- Write-Output $result.Body
149- }
150- else
151- {
152- $getTask = $client.StorageAccounts.ListKeysAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
153- Write-Output $getTask.Result.StorageAccountKeys
154- }
102+ $getTask = $client.StorageAccounts.ListKeysWithHttpMessagesAsync ($ResourceGroupName , $name )
103+ Write-Output $getTask.Result.Body.Keys
155104 }
156105 END {}
157106}
@@ -169,15 +118,8 @@ function Remove-AzureRmStorageAccount
169118 $version = $client.GetType ().Assembly.GetName().Version
170119 }
171120 PROCESS {
172- if ($version.Major -gt 3 )
173- {
174- $getTask = $client.StorageAccounts.DeleteWithHttpMessagesAsync ($ResourceGroupName , $name , $null , [System.Threading.CancellationToken ]::None)
175- }
176- else
177- {
178- $getTask = $client.StorageAccounts.DeleteAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
179- }
180- $sa = $getTask.Result
121+ $getTask = $client.StorageAccounts.DeleteWithHttpMessagesAsync ($ResourceGroupName , $name )
122+ $sa = $getTask.Result.Body
181123 }
182124 END {}
183125
@@ -188,37 +130,23 @@ function Get-Context
188130 return [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider ]::Instance.Profile.DefaultContext
189131}
190132
191- function Parse-Type
192- {
193- param ([string ] $type , [int ] $majorVersion )
194- $type = $type.Replace (" _" , " " )
195- if ($majorVersion -lt 5 )
196- {
197- $returnSkuName = [System.Enum ]::Parse([Microsoft.Azure.Management.Storage.Models.AccountType ], $type )
198- }
199- else
200- {
201- $returnSkuName = [System.Enum ]::Parse([Microsoft.Azure.Management.Storage.Models.SkuName ], $type )
202- }
203- return $returnSkuName ;
204- }
133+ function Parse-Type
134+ {
135+ param ([string ] $type )
136+ $type = $type.Replace (" _" , " " )
137+ $returnSkuName = [System.Enum ]::Parse([Microsoft.Azure.Management.Storage.Version2017 _10_01.Models.SkuName ], $type )
138+ return $returnSkuName ;
139+ }
205140
206141function Get-StorageClient
207142{
208143 param ([Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext ] $context )
209144 $factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession ]::Instance.ClientFactory
210145 [System.Type []]$types = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContext ], [string ]
211- $storageClient = [Microsoft.Azure.Management.Storage.StorageManagementClient ]
146+ $storageClient = [Microsoft.Azure.Management.Storage.Version2017 _10_01. StorageManagementClient ]
212147 $storageVersion = [System.Reflection.Assembly ]::GetAssembly($storageClient ).GetName().Version
213- if ($storageVersion.Major -gt 3 )
214- {
215- $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateArmClient" , $types )
216- }
217- else
218- {
219- $method = [Microsoft.Azure.Commands.Common.Authentication.IHyakClientFactory ].GetMethod(" CreateClient" , $types )
220- }
221- $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Storage.StorageManagementClient ])
148+ $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateArmClient" , $types )
149+ $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Storage.Version2017 _10_01.StorageManagementClient ])
222150 $arguments = $context , [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureEnvironment + Endpoint ]::ResourceManager
223151 $client = $closedMethod.Invoke ($factory , $arguments )
224152 return $client
0 commit comments