1
+
2
+ function Get-AzureRmStorageAccount
3
+ {
4
+
5
+ [CmdletBinding ()]
6
+ param (
7
+ [string ] [Parameter (Position = 0 , ValueFromPipelineByPropertyName = $true )] $ResourceGroupName ,
8
+ [string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] $Name )
9
+ BEGIN {
10
+ $context = Get-Context
11
+ $client = Get-StorageClient $context
12
+ }
13
+ PROCESS {
14
+ $getTask = $client.StorageAccounts.GetPropertiesAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
15
+ $sa = $getTask.Result
16
+ $account = Get-StorageAccount $sa $ResourceGroupName
17
+ Write-Output $account
18
+ }
19
+ END {}
20
+
21
+ }
22
+
23
+ function New-AzureRmStorageAccount
24
+ {
25
+ [CmdletBinding ()]
26
+ param (
27
+ [string ] [Parameter (Position = 0 , ValueFromPipelineByPropertyName = $true )] $ResourceGroupName ,
28
+ [string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] $Name ,
29
+ [string ] [Parameter (Position = 2 , ValueFromPipelineByPropertyName = $true )] $Location ,
30
+ [string ] [Parameter (Position = 3 , ValueFromPipelineByPropertyName = $true )] $Type )
31
+ BEGIN {
32
+ $context = Get-Context
33
+ $client = Get-StorageClient $context
34
+ }
35
+ PROCESS {
36
+ $createParms = New-Object - Type Microsoft.Azure.Management.Storage.Models.StorageAccountCreateParameters
37
+ $createParms.AccountType = [Microsoft.Azure.Management.Storage.Models.AccountType ]::StandardLRS
38
+ $createParms.Location = $Location
39
+ $getTask = $client.StorageAccounts.CreateAsync ($ResourceGroupName , $name , $createParms , [System.Threading.CancellationToken ]::None)
40
+ $sa = $getTask.Result
41
+ $account = Get-StorageAccount $ResourceGroupName $Name
42
+ Write-Output $account
43
+ }
44
+ END {}
45
+
46
+ }
47
+
48
+ function Get-AzureRmStorageAccountKey
49
+ {
50
+ [CmdletBinding ()]
51
+ param (
52
+ [string ] [Parameter (Position = 0 , ValueFromPipelineByPropertyName = $true )] $ResourceGroupName ,
53
+ [string ] [Parameter (Position = 1 , ValueFromPipelineByPropertyName = $true )] $Name )
54
+ BEGIN {
55
+ $context = Get-Context
56
+ $client = Get-StorageClient $context
57
+ }
58
+ PROCESS {
59
+ $getTask = $client.StorageAccounts.ListKeysAsync ($ResourceGroupName , $name , [System.Threading.CancellationToken ]::None)
60
+ Write-Output $getTask.Result.StorageAccountKeys
61
+ }
62
+ END {}
63
+ }
64
+
65
+ function Get-Context
66
+ {
67
+ [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ]$context = $null
68
+ $profile = [Microsoft.WindowsAzure.Commands.Common.AzureRmProfileProvider ]::Instance.Profile
69
+ if ($profile -ne $null )
70
+ {
71
+ $context = $profile.Context
72
+ }
73
+
74
+ return $context
75
+ }
76
+
77
+ function Get-StorageClient
78
+ {
79
+ param ([Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ] $context )
80
+ $factory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession ]::ClientFactory
81
+ [System.Type []]$types = [Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext ], [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]
82
+ $method = [Microsoft.Azure.Commands.Common.Authentication.IClientFactory ].GetMethod(" CreateClient" , $types )
83
+ $closedMethod = $method.MakeGenericMethod ([Microsoft.Azure.Management.Storage.StorageManagementClient ])
84
+ $arguments = $context , [Microsoft.Azure.Commands.Common.Authentication.Models.AzureEnvironment + Endpoint ]::ResourceManager
85
+ $client = $closedMethod.Invoke ($factory , $arguments )
86
+ return $client
87
+ }
88
+
89
+ function Get-StorageAccount {
90
+ param ([string ] $resourceGroupName , [string ] $name )
91
+ $sa = New-Object PSObject - Property @ {" Name" = $name ; " ResourceGroupName" = $resourceGroupName }
92
+ return $sa
93
+ }
0 commit comments