Skip to content

Commit ab63700

Browse files
authored
Merge pull request #16 from IanB111/master
This closes #15
2 parents 37f6262 + b973e2c commit ab63700

5 files changed

Lines changed: 149 additions & 44 deletions

File tree

InvokeMasterScript.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ Set-ExecutionPolicy -ExecutionPolicy Unrestricted
66
-DeploymentGuid "<Replace with your DeploymentGUID, eg..cc7a4584-30c3-4161-b717-053f9ca7cc65>" `
77
-OmsWorkspaceID "<Replace with your OMS Workspace ID found on the log analytics settings>" `
88
-OMSSharedKey "<Replace with your OMS Workspace Shared Key found on the log analytics settings>" `
9-
-azureStackAdminUsername "<replace with your service admin account to access the admin portal/apis>" `
10-
-azureStackAdminPassword "<replace with your service admin password>" `
119
-CloudName "<Replace with your Cloud Name, this is how many data points are pivoted in the views>" `
12-
-Region "<replace with your region name specified in deploymet>" `
13-
-Fqdn "<replace with your FQDN which follows the region name in your URL, eg.. azurestack.corp.microsoft.com>" `
14-
-OEM "<replace with your hardware vendor name>"
10+
-Region "<Replace with your region name specified in deploymet>" `
11+
-Fqdn "<Replace with your FQDN which follows the region name in your URL, eg.. azurestack.corp.microsoft.com>" `
12+
-OEM "<Replace with your hardware vendor name>" `
13+
#Uncomment the below 2 lines if using Admin Credentials to gather data
14+
#-azureStackAdminUsername "<Replace with your service admin account to access the admin portal/apis>" `
15+
#-azureStackAdminPassword "<Replace with your service admin password>"
16+
#Uncomment the below 3 lines if using a SPN Cert to gather data
17+
#-CertificateThumbprint "<Replace with the thumbprint of your cert used for SPN>" `
18+
#-ApplicationId "<Replace with the ClientID of the SPN>" `
19+
#-TenantId "<Replace with the TenantId for the AzureStack>"
1520

1621

1722

MasterScript.ps1

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ This script is meant to be called from an ARM template.
2626
#>
2727
[CmdletBinding()]
2828
param(
29-
[Parameter(Mandatory = $true)]
29+
[Parameter( Mandatory = $true)]
3030
[string] $DeploymentGuid,
3131
[Parameter(Mandatory = $true)]
3232
[string] $OMSWorkspaceID,
3333
[Parameter(Mandatory = $true)]
3434
[string] $OMSSharedKey,
35-
[Parameter(Mandatory = $true)]
35+
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
3636
[string] $azureStackAdminUsername,
37-
[Parameter(Mandatory = $true)]
37+
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
3838
[string] $azureStackAdminPassword,
3939
[Parameter(Mandatory = $true)]
4040
[string] $CloudName,
@@ -43,11 +43,19 @@ param(
4343
[Parameter(Mandatory = $true)]
4444
[string] $Fqdn,
4545
[Parameter(Mandatory = $true)]
46-
[string] $Oem
46+
[string] $Oem,
47+
[Parameter(ParameterSetName='CertSPN',Mandatory = $true)]
48+
[string] $CertificateThumbprint,
49+
[Parameter(ParameterSetName='CertSPN',Mandatory = $true)]
50+
[string] $ApplicationId,
51+
[Parameter(ParameterSetName='CertSPN',Mandatory = $true)]
52+
[string] $TenantId
4753

4854
)
49-
50-
$azureStackAdminPasswordSecureString = $azureStackAdminPassword | ConvertTo-SecureString -Force -AsPlainText
55+
if($pscmdlet.ParameterSetName -eq "AdminAccount")
56+
{
57+
$azureStackAdminPasswordSecureString = $azureStackAdminPassword | ConvertTo-SecureString -Force -AsPlainText
58+
}
5159

5260
cd c:\
5361

@@ -74,26 +82,49 @@ Install-Module -Name Azs.Infrastructureinsights.Admin -Force
7482
Install-Module -Name Azs.Update.Admin -Force
7583
Install-Module -Name Azs.Fabric.Admin -Force
7684

77-
# store data required by scheduled task in files.
78-
$info = @{
79-
DeploymentGuid = $DeploymentGuid;
80-
CloudName = $CloudName;
81-
Region = $Region;
82-
Fqdn = $Fqdn;
83-
OmsWorkspaceID = $OMSWorkspaceID;
84-
OmsSharedKey = $OMSSharedKey;
85-
AzureStackAdminUsername = $azureStackAdminUsername;
86-
AzureStackAdminPassword = $azureStackAdminPassword;
87-
Oem = $Oem;
85+
86+
Switch($pscmdlet.ParameterSetName)
87+
{
88+
"AdminAccount" {
89+
# store data required by scheduled task to use AdminAccount in files.
90+
$info = @{
91+
ParameterSet = $pscmdlet.ParameterSetName;
92+
DeploymentGuid = $DeploymentGuid;
93+
CloudName = $CloudName;
94+
Region = $Region;
95+
Fqdn = $Fqdn;
96+
OmsWorkspaceID = $OMSWorkspaceID;
97+
OmsSharedKey = $OMSSharedKey;
98+
Oem = $Oem;
99+
AzureStackAdminUsername = $azureStackAdminUsername;
100+
101+
}
102+
#store passwords in txt files.
103+
$passwordText = $azureStackAdminPasswordSecureString | ConvertFrom-SecureString
104+
Set-Content -Path "C:\AZSAdminOMSInt\azspassword_$CloudName.txt" -Value $passwordText
105+
}
106+
107+
"CertSPN" {
108+
# store data required by scheduled task to use CertSPN in files.
109+
$info = @{
110+
ParameterSet = $pscmdlet.ParameterSetName;
111+
DeploymentGuid = $DeploymentGuid;
112+
CloudName = $CloudName;
113+
Region = $Region;
114+
Fqdn = $Fqdn;
115+
OmsWorkspaceID = $OMSWorkspaceID;
116+
OmsSharedKey = $OMSSharedKey;
117+
Oem = $Oem;
118+
CertificateThumbprint = $CertificateThumbprint;
119+
ApplicationId = $ApplicationId;
120+
TenantId = $TenantId;
121+
}
122+
}
88123
}
89124

90125
$infoJson = ConvertTo-Json $info
91126
Set-Content -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" -Value $infoJson
92127

93-
#store passwords in txt files.
94-
$passwordText = $azureStackAdminPasswordSecureString | ConvertFrom-SecureString
95-
Set-Content -Path "C:\AZSAdminOMSInt\azspassword_$CloudName.txt" -Value $passwordText
96-
97128

98129
#Download Azure Stack Tools VNext
99130
cd c:\AZSAdminOMSInt

OpsDataToOMS.ps1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Import-Module -Name Azs.Update.Admin -Force
1313
Import-Module -Name Azs.Fabric.Admin -Force
1414

1515

16+
1617
#OMS Authentication Variables
1718

1819
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" | ConvertFrom-Json
@@ -21,12 +22,26 @@ $OMSSharedKey = $info.OmsSharedKey
2122

2223

2324
#Cloud2 Authentication details
25+
$Authtype = $info.ParameterSet
2426
$Location2 = $info.Region
2527
$cloudName2 = $info.CloudName
2628
$State2 = "active"
27-
$UserName2= $info.AzureStackAdminUsername
28-
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
29-
$Credential2=New-Object PSCredential($UserName2,$Password2)
29+
Switch($Authtype)
30+
{
31+
#Set to AdminAccount or not set(old info file)
32+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
33+
$UserName2= $info.AzureStackAdminUsername
34+
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
35+
$Credential2=New-Object PSCredential($UserName2,$Password2)
36+
}
37+
#Using CertSPN
38+
"CertSPN"{
39+
$CertificateThumbprint2 = $info.CertificateThumbprint
40+
$ApplicationId2 = $info.ApplicationId
41+
$TenantId2 = $info.TenantId
42+
}
43+
}
44+
3045

3146
$deploymentGuid = $info.DeploymentGuid
3247
$api = "adminmanagement"
@@ -37,7 +52,18 @@ $AzSOEM = $info.Oem
3752
##############################################################################################################
3853
# Get Data via PS for Cloud 2
3954
Add-AzureRMEnvironment -Name "$cloudName2" -ArmEndpoint $AzureStackAdminEndPoint
40-
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
55+
Switch($Authtype)
56+
{
57+
#Set to AdminAccount or not set(old info file)
58+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
59+
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
60+
}
61+
#Using CertSPN
62+
"CertSPN"{
63+
Add-AzureRmAccount -Environment $cloudName2 -ServicePrincipal -CertificateThumbprint $CertificateThumbprint2 -ApplicationId $ApplicationId2 -TenantId $TenantId2
64+
}
65+
}
66+
4167

4268

4369
##Get Alerts

uploadToOMS.ps1

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ $OMSWorkspaceId = $info.OmsWorkspaceID
2020
$OMSSharedKey = $info.OmsSharedKey
2121

2222
#Cloud2 Authentication details
23+
$Authtype = $info.ParameterSet
2324
$Location2 = $info.Region
2425
$cloudName2 = $info.CloudName
2526
$State2 = "active"
26-
$UserName2= $info.AzureStackAdminUsername
27-
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
28-
$Credential2=New-Object PSCredential($UserName2,$Password2)
27+
Switch($Authtype)
28+
{
29+
#Set to AdminAccount or not set(old info file)
30+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
31+
$UserName2= $info.AzureStackAdminUsername
32+
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
33+
$Credential2=New-Object PSCredential($UserName2,$Password2)
34+
}
35+
#Using CertSPN
36+
"CertSPN"{
37+
$CertificateThumbprint2 = $info.CertificateThumbprint
38+
$ApplicationId2 = $info.ApplicationId
39+
$TenantId2 = $info.TenantId
40+
}
41+
}
42+
2943

3044
$deploymentGuid = $info.DeploymentGuid
3145
$api = "adminmanagement"
@@ -40,7 +54,17 @@ $AzSOEM = $info.Oem
4054
##############################################################################################################
4155
# Get Data via PS for Cloud 2
4256
Add-AzureRMEnvironment -Name $cloudName2 -ArmEndpoint $AzureStackAdminEndPoint
43-
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
57+
Switch($Authtype)
58+
{
59+
#Set to AdminAccount or not set(old info file)
60+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
61+
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
62+
}
63+
#Using CertSPN
64+
"CertSPN"{
65+
Add-AzureRmAccount -Environment $cloudName2 -ServicePrincipal -CertificateThumbprint $CertificateThumbprint2 -ApplicationId $ApplicationId2 -TenantId $TenantId2
66+
}
67+
}
4468

4569
#################################################################################
4670
# USAGE DATA

usagesummaryjson.ps1

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Export-AzureStackUsage {
2828
[Parameter(Mandatory = $true)]
2929
[String]
3030
$AzureStackDomain ,
31-
[Parameter(Mandatory = $true)]
31+
[Parameter(Mandatory = $false)]
3232
[String]
3333
$AADDomain ,
3434
[Parameter(Mandatory = $false)]
@@ -201,22 +201,41 @@ $usageStartTime = $dayBeforeYesterday.ToShortDateString()
201201
$usageEndTime = $yesterday.ToShortDateString()
202202

203203
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" | ConvertFrom-Json
204-
$Username = $info.AzureStackAdminUsername
205-
$Password= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
206-
$aadCred = New-Object PSCredential($Username, $Password)
204+
$Authtype = $info.ParameterSet
207205
$cloudName2 = $info.CloudName
208206
$Location2 = $info.Region
209207
$api = "adminmanagement"
210208
$AzureStackDomain = $info.Fqdn
211209
$AzureStackAdminEndPoint = 'https://{0}.{1}.{2}' -f $api, $Location2, $AzureStackDomain
212-
213-
214-
$pos = $Username.IndexOf('@')
215-
$aadDomain = $Username.Substring($pos + 1)
210+
Switch($Authtype)
211+
{
212+
#Set to AdminAccount or not set(old info file)
213+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
214+
$Username2 = $info.AzureStackAdminUsername
215+
$Password2 = Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
216+
$Credential2 = New-Object PSCredential($Username2, $Password2)
217+
}
218+
#Using CertSPN
219+
"CertSPN"{
220+
$CertificateThumbprint2 = $info.CertificateThumbprint
221+
$ApplicationId2 = $info.ApplicationId
222+
$TenantId2 = $info.TenantId
223+
}
224+
}
216225

217226

218227
Add-AzureRMEnvironment -Name $cloudName2 -ArmEndpoint $AzureStackAdminEndPoint
219-
Login-AzureRmAccount -EnvironmentName $cloudName2 -Credential $aadCred
228+
Switch($Authtype)
229+
{
230+
#Set to AdminAccount or not set(old info file)
231+
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
232+
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
233+
}
234+
#Using CertSPN
235+
"CertSPN"{
236+
Add-AzureRmAccount -Environment $cloudName2 -ServicePrincipal -CertificateThumbprint $CertificateThumbprint2 -ApplicationId $ApplicationId2 -TenantId $TenantId2
237+
}
238+
}
220239

221240
# store the result of the usage api records for the time period from the day before yesterday to yesterday in a json file.
222-
Export-AzureStackUsage -StartTime $usageStartTime -EndTime $usageEndTime -AzureStackDomain $info.Fqdn -AADDomain $aadDomain -Region $info.Region -Credential $aadCred -Granularity Hourly -Force -CloudName1 $info.CloudName
241+
Export-AzureStackUsage -StartTime $usageStartTime -EndTime $usageEndTime -AzureStackDomain $AzureStackDomain -Region $Location2 -Granularity Hourly -Force -CloudName1 $cloudName2

0 commit comments

Comments
 (0)