88 . SYNOPSIS
99 Registers all providers on the all subscription
1010#>
11- function Register-AllAzureRmProvidersOnAllSubscriptions
12- {
13- foreach ($s in (Get-AzureRmSubscription ))
14- {
11+ function Register-AllAzureRmProvidersOnAllSubscriptions {
12+ foreach ($s in (Get-AzureRmSubscription )) {
1513 Select-AzureRmSubscription - SubscriptionId $s.SubscriptionId | Out-Null
1614 Write-Progress $ ($s.SubscriptionId + " : " + $s.SubscriptionName )
17- Register-AllAzureRmProviders
18- }
15+ Register-AllAzureRmProviders
16+ }
1917}
2018
2119Export-ModuleMember Register-AllAzureRmProvidersOnAllSubscriptions
@@ -24,8 +22,7 @@ Export-ModuleMember Register-AllAzureRmProvidersOnAllSubscriptions
2422 . SYNOPSIS
2523 Registers all providers on the newly created subscription
2624#>
27- function Register-AllAzureRmProviders
28- {
25+ function Register-AllAzureRmProviders {
2926 Get-AzureRmResourceProvider - ListAvailable | Register-AzureRmResourceProvider - Force
3027}
3128
@@ -35,11 +32,10 @@ Export-ModuleMember Register-AllAzureRmProviders
3532 . SYNOPSIS
3633 Obtains Aazure Active Directory tenant that was used when deploying the Azure Stack instance
3734#>
38- function Get-AzureStackAadTenant
39- {
35+ function Get-AzureStackAadTenant {
4036 param (
4137 [parameter (mandatory = $true , HelpMessage = " Azure Stack One Node host address or name such as '1.2.3.4'" )]
42- [string ] $HostComputer ,
38+ [string ] $HostComputer ,
4339 [Parameter (HelpMessage = " The Admin ARM endpoint of the Azure Stack Environment" )]
4440 [string ] $ArmEndpoint = ' https://api.local.azurestack.external' ,
4541 [Parameter (HelpMessage = " The Domain suffix of the environment VMs" )]
@@ -70,16 +66,16 @@ function Get-AzureStackAadTenant
7066 Write-Verbose " Remoting to the Azure Stack host $HostComputer ..." - Verbose
7167 return Invoke-Command - ComputerName " $HostComputer " - Credential $credential - ScriptBlock `
7268 {
73- Write-Verbose " Retrieving Azure Stack configuration..." - Verbose
74- $configFile = Get-ChildItem - Path C:\EceStore - Recurse | ? {-not $_.PSIsContainer } | sort Length - Descending | select - First 1
75- $customerConfig = [xml ] (Get-Content - Path $configFile.FullName )
76-
77- $Parameters = $customerConfig.CustomerConfiguration
78- $fabricRole = $Parameters.Role.Roles.Role | ? {$_.Id -eq " Fabric" }
79- $allFabricRoles = $fabricRole.Roles.ChildNodes
80- $idProviderRole = $allFabricRoles | ? {$_.Id -eq " IdentityProvider" }
81- $idProviderRole.PublicInfo.AADTenant.Id
82- }
69+ Write-Verbose " Retrieving Azure Stack configuration..." - Verbose
70+ $configFile = Get-ChildItem - Path C:\EceStore - Recurse | ? {-not $_.PSIsContainer } | sort Length - Descending | select - First 1
71+ $customerConfig = [xml ] (Get-Content - Path $configFile.FullName )
72+
73+ $Parameters = $customerConfig.CustomerConfiguration
74+ $fabricRole = $Parameters.Role.Roles.Role | ? {$_.Id -eq " Fabric" }
75+ $allFabricRoles = $fabricRole.Roles.ChildNodes
76+ $idProviderRole = $allFabricRoles | ? {$_.Id -eq " IdentityProvider" }
77+ $idProviderRole.PublicInfo.AADTenant.Id
78+ }
8379}
8480
8581Export-ModuleMember Get-AzureStackAadTenant
@@ -88,17 +84,26 @@ Export-ModuleMember Get-AzureStackAadTenant
8884 . SYNOPSIS
8985 Adds Azure Stack environment to use with AzureRM command-lets when targeting Azure Stack
9086#>
91- function Add-AzureStackAzureRmEnvironment
92- {
87+ function Add-AzureStackAzureRmEnvironment {
9388 param (
9489 [parameter (mandatory = $true , HelpMessage = " AAD Tenant name or ID used when deploying Azure Stack such as 'mydirectory.onmicrosoft.com'" )]
95- [string ] $AadTenant ,
90+ [string ] $AadTenant ,
9691 [Parameter (HelpMessage = " The Admin ARM endpoint of the Azure Stack Environment" )]
9792 [string ] $ArmEndpoint = ' https://api.local.azurestack.external' ,
9893 [parameter (HelpMessage = " Azure Stack environment name for use with AzureRM commandlets" )]
9994 [string ] $Name = " AzureStack"
10095 )
10196
97+ if (! $ARMEndpoint.Contains (' https://' )){
98+ if ($ARMEndpoint.Contains (' http://' )){
99+ $ARMEndpoint = $ARMEndpoint.Substring (7 )
100+ $ARMEndpoint = ' https://' + $ARMEndpoint
101+
102+ }else {
103+ $ARMEndpoint = ' https://' + $ARMEndpoint
104+ }
105+ }
106+
102107 $Domain = " "
103108 try {
104109 $uriARMEndpoint = [System.Uri ] $ArmEndpoint
@@ -117,36 +122,34 @@ function Add-AzureStackAzureRmEnvironment
117122
118123 $AzureKeyVaultDnsSuffix = " vault.$ ( $stackdomain ) " .ToLowerInvariant()
119124 $AzureKeyVaultServiceEndpointResourceId = $ (" https://vault.$stackdomain " .ToLowerInvariant())
120- $StorageEndpointSuffix = ($stackdomain ).ToLowerInvariant()
121- $aadAuthorityEndpoint = $endpoints.authentication.loginEndpoint
122-
123- $azureEnvironmentParams = @ {
124- Name = $Name
125- ActiveDirectoryEndpoint = $endpoints.authentication.loginEndpoint.TrimEnd (' /' ) + " /"
126- ActiveDirectoryServiceEndpointResourceId = $endpoints.authentication.audiences [0 ]
127- AdTenant = $AadTenant
128- ResourceManagerEndpoint = $ResourceManagerEndpoint
129- GalleryEndpoint = $endpoints.galleryEndpoint
130- GraphEndpoint = $endpoints.graphEndpoint
131- GraphAudience = $endpoints.graphEndpoint
132- StorageEndpointSuffix = $StorageEndpointSuffix
133- AzureKeyVaultDnsSuffix = $AzureKeyVaultDnsSuffix
134- AzureKeyVaultServiceEndpointResourceId = $AzureKeyVaultServiceEndpointResourceId
135- EnableAdfsAuthentication = $aadAuthorityEndpoint.TrimEnd (" /" ).EndsWith(" /adfs" , [System.StringComparison ]::OrdinalIgnoreCase)
136- }
125+ $StorageEndpointSuffix = ($stackdomain ).ToLowerInvariant()
126+ $aadAuthorityEndpoint = $endpoints.authentication.loginEndpoint
127+
128+ $azureEnvironmentParams = @ {
129+ Name = $Name
130+ ActiveDirectoryEndpoint = $endpoints.authentication.loginEndpoint.TrimEnd (' /' ) + " /"
131+ ActiveDirectoryServiceEndpointResourceId = $endpoints.authentication.audiences [0 ]
132+ AdTenant = $AadTenant
133+ ResourceManagerEndpoint = $ResourceManagerEndpoint
134+ GalleryEndpoint = $endpoints.galleryEndpoint
135+ GraphEndpoint = $endpoints.graphEndpoint
136+ GraphAudience = $endpoints.graphEndpoint
137+ StorageEndpointSuffix = $StorageEndpointSuffix
138+ AzureKeyVaultDnsSuffix = $AzureKeyVaultDnsSuffix
139+ AzureKeyVaultServiceEndpointResourceId = $AzureKeyVaultServiceEndpointResourceId
140+ EnableAdfsAuthentication = $aadAuthorityEndpoint.TrimEnd (" /" ).EndsWith(" /adfs" , [System.StringComparison ]::OrdinalIgnoreCase)
141+ }
137142
138- $armEnv = Get-AzureRmEnvironment - Name $Name
139- if ($armEnv -ne $null )
140- {
141- Write-Verbose " Updating AzureRm environment $Name " - Verbose
142- Remove-AzureRmEnvironment - Name $Name | Out-Null
143- }
144- else
145- {
146- Write-Verbose " Adding AzureRm environment $Name " - Verbose
147- }
143+ $armEnv = Get-AzureRmEnvironment - Name $Name
144+ if ($armEnv -ne $null ) {
145+ Write-Verbose " Updating AzureRm environment $Name " - Verbose
146+ Remove-AzureRmEnvironment - Name $Name | Out-Null
147+ }
148+ else {
149+ Write-Verbose " Adding AzureRm environment $Name " - Verbose
150+ }
148151
149- return Add-AzureRmEnvironment @azureEnvironmentParams
152+ return Add-AzureRmEnvironment @azureEnvironmentParams
150153}
151154
152155Export-ModuleMember Add-AzureStackAzureRmEnvironment
@@ -155,11 +158,10 @@ Export-ModuleMember Add-AzureStackAzureRmEnvironment
155158 . SYNOPSIS
156159 Obtains Azure Stack NAT address from the Azure Stack One Node instance
157160#>
158- function Get-AzureStackNatServerAddress
159- {
161+ function Get-AzureStackNatServerAddress {
160162 param (
161163 [parameter (mandatory = $true , HelpMessage = " Azure Stack One Node host address or name such as '1.2.3.4'" )]
162- [string ] $HostComputer ,
164+ [string ] $HostComputer ,
163165 [Parameter (HelpMessage = " The Admin ARM endpoint of the Azure Stack Environment" )]
164166 [string ] $ArmEndpoint = ' https://api.local.azurestack.external' ,
165167 [Parameter (HelpMessage = " The Domain suffix of the environment VMs" )]
@@ -194,13 +196,13 @@ function Get-AzureStackNatServerAddress
194196 Write-Verbose " Remoting to the Azure Stack host $HostComputer ..." - Verbose
195197 return Invoke-Command - ComputerName " $HostComputer " - Credential $credential - ScriptBlock `
196198 {
197- Write-Verbose " Remoting to the Azure Stack NAT server $using :nat ..." - Verbose
198- Invoke-Command - ComputerName " $using :nat " - Credential $using :credential - ScriptBlock `
199+ Write-Verbose " Remoting to the Azure Stack NAT server $using :nat ..." - Verbose
200+ Invoke-Command - ComputerName " $using :nat " - Credential $using :credential - ScriptBlock `
199201 {
200- Write-Verbose " Obtaining external IP..." - Verbose
201- Get-NetIPConfiguration | ? { $_.IPv4DefaultGateway -ne $null } | foreach { $_.IPv4Address.IPAddress }
202- }
203- }
202+ Write-Verbose " Obtaining external IP..." - Verbose
203+ Get-NetIPConfiguration | ? { $_.IPv4DefaultGateway -ne $null } | foreach { $_.IPv4Address.IPAddress }
204+ }
205+ }
204206}
205207
206208Export-ModuleMember Get-AzureStackNatServerAddress
@@ -209,14 +211,13 @@ Export-ModuleMember Get-AzureStackNatServerAddress
209211 . SYNOPSIS
210212 Add VPN connection to an Azure Stack instance
211213#>
212- function Add-AzureStackVpnConnection
213- {
214+ function Add-AzureStackVpnConnection {
214215 param (
215- [parameter (HelpMessage = " Azure Stack VPN Connection Name such as 'my-poc'" )]
216- [string ] $ConnectionName = " azurestack" ,
216+ [parameter (HelpMessage = " Azure Stack VPN Connection Name such as 'my-poc'" )]
217+ [string ] $ConnectionName = " azurestack" ,
217218
218- [parameter (mandatory = $true , HelpMessage = " External IP of the Azure Stack NAT VM such as '1.2.3.4'" )]
219- [string ] $ServerAddress ,
219+ [parameter (mandatory = $true , HelpMessage = " External IP of the Azure Stack NAT VM such as '1.2.3.4'" )]
220+ [string ] $ServerAddress ,
220221
221222 [parameter (mandatory = $true , HelpMessage = " Administrator password used to deploy this Azure Stack instance" )]
222223 [securestring ] $Password
@@ -228,8 +229,7 @@ function Add-AzureStackVpnConnection
228229 rasdial $ConnectionName / d
229230 Remove-VpnConnection - name $ConnectionName - Force - ErrorAction Ignore
230231 }
231- else
232- {
232+ else {
233233 Write-Verbose " Creating Azure Stack VPN connection named $ConnectionName " - Verbose
234234 }
235235
@@ -251,11 +251,10 @@ Export-ModuleMember Add-AzureStackVpnConnection
251251 . SYNOPSIS
252252 Connects to Azure Stack via VPN
253253#>
254- function Connect-AzureStackVpn
255- {
254+ function Connect-AzureStackVpn {
256255 param (
257- [parameter (HelpMessage = " Azure Stack VPN Connection Name such as 'my-poc'" )]
258- [string ] $ConnectionName = " azurestack" ,
256+ [parameter (HelpMessage = " Azure Stack VPN Connection Name such as 'my-poc'" )]
257+ [string ] $ConnectionName = " azurestack" ,
259258 [Parameter (HelpMessage = " The Admin ARM endpoint of the Azure Stack Environment" )]
260259 [string ] $ArmEndpoint = ' https://api.local.azurestack.external' ,
261260 [Parameter (HelpMessage = " The Domain suffix of the environment VMs" )]
@@ -303,10 +302,8 @@ function Connect-AzureStackVpn
303302 Write-Verbose " Retrieving Azure Stack Root Authority certificate..." - Verbose
304303 $cert = Invoke-Command - ComputerName " $Remote .$Domain " - ScriptBlock { Get-ChildItem cert:\currentuser\root | where-object {$_.Subject -eq " CN=AzureStackCertificationAuthority, DC=AzureStack, DC=local" } } - Credential $credential
305304
306- if ($cert -ne $null )
307- {
308- if ($cert.GetType ().IsArray)
309- {
305+ if ($cert -ne $null ) {
306+ if ($cert.GetType ().IsArray) {
310307 $cert = $cert [0 ] # take any that match the subject if multiple certs were deployed
311308 }
312309
@@ -320,10 +317,9 @@ function Connect-AzureStackVpn
320317
321318 Write-Progress " LOOK FOR CERT ACCEPTANCE PROMPT ON YOUR SCREEN!"
322319
323- Import-Certificate - CertStoreLocation cert:\currentuser\root - FilePath $certFilePath
320+ Import-Certificate - CertStoreLocation cert:\currentuser\root - FilePath $certFilePath
324321 }
325- else
326- {
322+ else {
327323 Write-Error " Certificate has not been retrieved!"
328324 }
329325}
@@ -334,14 +330,13 @@ Export-ModuleMember Connect-AzureStackVpn
334330 . SYNOPSIS
335331 Retrieve the admin token and subscription ID needed to make REST calls directly to Azure Resource Manager
336332#>
337- function Get-AzureStackAdminSubTokenHeader
338- {
333+ function Get-AzureStackAdminSubTokenHeader {
339334 param (
340- [parameter (HelpMessage = " Name of the Azure Stack Environment" )]
341- [string ] $EnvironmentName = " AzureStack" ,
335+ [parameter (HelpMessage = " Name of the Azure Stack Environment" )]
336+ [string ] $EnvironmentName = " AzureStack" ,
342337
343- [parameter (mandatory = $true , HelpMessage = " TenantID of Identity Tenant" )]
344- [string ] $tenantID ,
338+ [parameter (mandatory = $true , HelpMessage = " TenantID of Identity Tenant" )]
339+ [string ] $tenantID ,
345340
346341 [parameter (HelpMessage = " Credentials to retrieve token header for" )]
347342 [System.Management.Automation.PSCredential ] $azureStackCredentials ,
@@ -354,6 +349,15 @@ function Get-AzureStackAdminSubTokenHeader
354349 $azureStackCredentials = Get-Credential
355350 }
356351
352+ if (! $ARMEndpoint.Contains (' https://' )){
353+ if ($ARMEndpoint.Contains (' http://' )){
354+ $ARMEndpoint = $ARMEndpoint.Substring (7 )
355+ $ARMEndpoint = ' https://' + $ARMEndpoint
356+ }else {
357+ $ARMEndpoint = ' https://' + $ARMEndpoint
358+ }
359+ }
360+
357361 $Domain = " "
358362 try {
359363 $uriARMEndpoint = [System.Uri ] $ArmEndpoint
@@ -400,13 +404,12 @@ function Get-AzureStackAdminSubTokenHeader
400404
401405Export-ModuleMember Get-AzureStackAdminSubTokenHeader
402406
403- function Get-AADTenantGUID ()
404- {
407+ function Get-AADTenantGUID () {
405408 param (
406409 [parameter (mandatory = $true , HelpMessage = " AAD Directory Tenant <myaadtenant.onmicrosoft.com>" )]
407- [string ] $AADTenantName = " " ,
410+ [string ] $AADTenantName = " " ,
408411 [parameter (mandatory = $false , HelpMessage = " Azure Cloud" )]
409- [ValidateSet (" AzureCloud" , " AzureChinaCloud" , " AzureUSGovernment" , " AzureGermanCloud" )]
412+ [ValidateSet (" AzureCloud" , " AzureChinaCloud" , " AzureUSGovernment" , " AzureGermanCloud" )]
410413 [string ] $AzureCloud = " AzureCloud"
411414 )
412415 $ADauth = (Get-AzureRmEnvironment - Name $AzureCloud ).ActiveDirectoryAuthority
0 commit comments