Skip to content

Commit 5289c82

Browse files
authored
Merge pull request #17 from IanB111/master
Adding support for TenantID with AdminCredentials
2 parents 5bd9e06 + d1d191d commit 5289c82

7 files changed

Lines changed: 427 additions & 397 deletions

File tree

InvokeMasterScript.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Set-ExecutionPolicy -ExecutionPolicy Unrestricted
1313
#Uncomment the below 2 lines if using Admin Credentials to gather data
1414
#-azureStackAdminUsername "<Replace with your service admin account to access the admin portal/apis>" `
1515
#-azureStackAdminPassword "<Replace with your service admin password>"
16-
#Uncomment the below 3 lines if using a SPN Cert to gather data
16+
#Uncomment the below 2 lines if using a SPN Cert to gather data
1717
#-CertificateThumbprint "<Replace with the thumbprint of your cert used for SPN>" `
1818
#-ApplicationId "<Replace with the ClientID of the SPN>" `
19+
#Uncomment the below line if using TenantID as part of sign in of the Management Endpoint, requried if using SPN
1920
#-TenantId "<Replace with the TenantId for the AzureStack>"
2021

2122

MasterScript.ps1

Lines changed: 141 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,141 @@
1-
<#
2-
.Synopsis
3-
4-
The script that gets called by the ARM template when it deploys a custom script extension.
5-
It sets up a scheduled task to upload usage data to OMS.
6-
7-
.DESCRIPTION
8-
9-
It Sets up git and download repository containing the necessary scripts, stores necessary
10-
information onto the host and then sets up a windows scheduled task to upload usage data
11-
daily.
12-
13-
.EXAMPLE
14-
This script is meant to be called from an ARM template.
15-
.\MasterScript `
16-
-DeploymentGuid <deployment guid> `
17-
-OMSWorkspaceID "myomsworkspaceGUID" `
18-
-OMSSharedKey "myomssharedkeyGUID" `
19-
-azureStackAdminUsername "serviceadmin@contoso.onmicrosoft.com" `
20-
-azureStackAdminPassword $Password `
21-
-CloudName "Cloud#1" `
22-
-Region "local" `
23-
-Fqdn "azurestack.external"
24-
-OEM "HPE"
25-
26-
#>
27-
[CmdletBinding()]
28-
param(
29-
[Parameter( Mandatory = $true)]
30-
[string] $DeploymentGuid,
31-
[Parameter(Mandatory = $true)]
32-
[string] $OMSWorkspaceID,
33-
[Parameter(Mandatory = $true)]
34-
[string] $OMSSharedKey,
35-
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
36-
[string] $azureStackAdminUsername,
37-
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
38-
[string] $azureStackAdminPassword,
39-
[Parameter(Mandatory = $true)]
40-
[string] $CloudName,
41-
[Parameter(Mandatory = $true)]
42-
[string] $Region,
43-
[Parameter(Mandatory = $true)]
44-
[string] $Fqdn,
45-
[Parameter(Mandatory = $true)]
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
53-
54-
)
55-
if($pscmdlet.ParameterSetName -eq "AdminAccount")
56-
{
57-
$azureStackAdminPasswordSecureString = $azureStackAdminPassword | ConvertTo-SecureString -Force -AsPlainText
58-
}
59-
60-
cd c:\
61-
62-
# install git
63-
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
64-
# refresh the PATH to recognize "choco" command
65-
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
66-
choco install git.install -y
67-
# refresh the PATH to recognize git
68-
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
69-
git clone "https://github.com/Azure-Samples/AzureStack-AdminPowerShell-OMSIntegration.git" C:\AZSAdminOMSInt
70-
71-
72-
# installing powershell modules for azure stack.
73-
# NuGet required for Set-PsRepository PSGallery.
74-
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
75-
Set-PsRepository PSGallery -InstallationPolicy Trusted
76-
Get-Module -ListAvailable | where-Object {$_.Name -like "Azure*"} | Uninstall-Module
77-
Install-Module -Name AzureRm.BootStrapper -Force
78-
Install-Module -Name AzureRm.Resources -Force
79-
Install-Module -Name AzureStack -Force
80-
Install-Module -Name AzureRM.AzureStackAdmin -Force
81-
Install-Module -Name Azs.Infrastructureinsights.Admin -Force
82-
Install-Module -Name Azs.Update.Admin -Force
83-
Install-Module -Name Azs.Fabric.Admin -Force
84-
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-
}
123-
}
124-
125-
$infoJson = ConvertTo-Json $info
126-
Set-Content -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" -Value $infoJson
127-
128-
129-
#Download Azure Stack Tools VNext
130-
cd c:\AZSAdminOMSInt
131-
invoke-webrequest https://github.com/Azure/AzureStack-Tools/archive/vnext.zip -OutFile vnext.zip
132-
expand-archive vnext.zip -DestinationPath . -Force
133-
134-
# schedule windows scheduled task
135-
cd C:\AZSAdminOMSInt
136-
& .\schedule_usage_upload.ps1 -CloudName $CloudName
1+
<#
2+
.Synopsis
3+
4+
The script that gets called by the ARM template when it deploys a custom script extension.
5+
It sets up a scheduled task to upload usage data to OMS.
6+
7+
.DESCRIPTION
8+
9+
It Sets up git and download repository containing the necessary scripts, stores necessary
10+
information onto the host and then sets up a windows scheduled task to upload usage data
11+
daily.
12+
13+
.EXAMPLE
14+
This script is meant to be called from an ARM template.
15+
.\MasterScript `
16+
-DeploymentGuid <deployment guid> `
17+
-OMSWorkspaceID "myomsworkspaceGUID" `
18+
-OMSSharedKey "myomssharedkeyGUID" `
19+
-azureStackAdminUsername "serviceadmin@contoso.onmicrosoft.com" `
20+
-azureStackAdminPassword $Password `
21+
-CloudName "Cloud#1" `
22+
-Region "local" `
23+
-Fqdn "azurestack.external"
24+
-OEM "HPE"
25+
26+
#>
27+
[CmdletBinding()]
28+
param(
29+
[Parameter( Mandatory = $true)]
30+
[string] $DeploymentGuid,
31+
[Parameter(Mandatory = $true)]
32+
[string] $OMSWorkspaceID,
33+
[Parameter(Mandatory = $true)]
34+
[string] $OMSSharedKey,
35+
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
36+
[string] $azureStackAdminUsername,
37+
[Parameter(ParameterSetName='AdminAccount',Mandatory = $true)]
38+
[string] $azureStackAdminPassword,
39+
[Parameter(Mandatory = $true)]
40+
[string] $CloudName,
41+
[Parameter(Mandatory = $true)]
42+
[string] $Region,
43+
[Parameter(Mandatory = $true)]
44+
[string] $Fqdn,
45+
[Parameter(Mandatory = $true)]
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+
[Parameter(ParameterSetName='AdminAccount',Mandatory = $false)]
53+
[string] $TenantId
54+
55+
)
56+
if($pscmdlet.ParameterSetName -eq "AdminAccount")
57+
{
58+
$azureStackAdminPasswordSecureString = $azureStackAdminPassword | ConvertTo-SecureString -Force -AsPlainText
59+
}
60+
61+
cd c:\
62+
63+
# install git
64+
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
65+
# refresh the PATH to recognize "choco" command
66+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
67+
choco install git.install -y
68+
# refresh the PATH to recognize git
69+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
70+
git clone "https://github.com/Azure-Samples/AzureStack-AdminPowerShell-OMSIntegration.git" C:\AZSAdminOMSInt
71+
72+
73+
# installing powershell modules for azure stack.
74+
# NuGet required for Set-PsRepository PSGallery.
75+
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
76+
Set-PsRepository PSGallery -InstallationPolicy Trusted
77+
Get-Module -ListAvailable | where-Object {$_.Name -like "Azure*"} | Uninstall-Module
78+
Install-Module -Name AzureRm.BootStrapper -Force
79+
Install-Module -Name AzureRm.Resources -Force
80+
Install-Module -Name AzureStack -Force
81+
Install-Module -Name AzureRM.AzureStackAdmin -Force
82+
Install-Module -Name Azs.Infrastructureinsights.Admin -Force
83+
Install-Module -Name Azs.Update.Admin -Force
84+
Install-Module -Name Azs.Fabric.Admin -Force
85+
86+
87+
Switch($pscmdlet.ParameterSetName)
88+
{
89+
"AdminAccount" {
90+
# store data required by scheduled task to use AdminAccount in files.
91+
$info = @{
92+
ParameterSet = $pscmdlet.ParameterSetName;
93+
DeploymentGuid = $DeploymentGuid;
94+
CloudName = $CloudName;
95+
Region = $Region;
96+
Fqdn = $Fqdn;
97+
OmsWorkspaceID = $OMSWorkspaceID;
98+
OmsSharedKey = $OMSSharedKey;
99+
Oem = $Oem;
100+
AzureStackAdminUsername = $azureStackAdminUsername;
101+
102+
}
103+
if($TenantId)
104+
{#If a TenantId was provided add it to the data that will be stored
105+
$info.Add("TenantId", $TenantId)
106+
}
107+
#store passwords in txt files.
108+
$passwordText = $azureStackAdminPasswordSecureString | ConvertFrom-SecureString
109+
Set-Content -Path "C:\AZSAdminOMSInt\azspassword_$CloudName.txt" -Value $passwordText
110+
}
111+
112+
"CertSPN" {
113+
# store data required by scheduled task to use CertSPN in files.
114+
$info = @{
115+
ParameterSet = $pscmdlet.ParameterSetName;
116+
DeploymentGuid = $DeploymentGuid;
117+
CloudName = $CloudName;
118+
Region = $Region;
119+
Fqdn = $Fqdn;
120+
OmsWorkspaceID = $OMSWorkspaceID;
121+
OmsSharedKey = $OMSSharedKey;
122+
Oem = $Oem;
123+
CertificateThumbprint = $CertificateThumbprint;
124+
ApplicationId = $ApplicationId;
125+
TenantId = $TenantId;
126+
}
127+
}
128+
}
129+
130+
$infoJson = ConvertTo-Json $info
131+
Set-Content -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" -Value $infoJson
132+
133+
134+
#Download Azure Stack Tools VNext
135+
cd c:\AZSAdminOMSInt
136+
invoke-webrequest https://github.com/Azure/AzureStack-Tools/archive/vnext.zip -OutFile vnext.zip
137+
expand-archive vnext.zip -DestinationPath . -Force
138+
139+
# schedule windows scheduled task
140+
cd C:\AZSAdminOMSInt
141+
& .\schedule_usage_upload.ps1 -CloudName $CloudName

OpsDataToOMS.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Switch($Authtype)
3333
$UserName2= $info.AzureStackAdminUsername
3434
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
3535
$Credential2=New-Object PSCredential($UserName2,$Password2)
36+
$TenantId2 = $info.TenantId
3637
}
3738
#Using CertSPN
3839
"CertSPN"{
@@ -56,8 +57,13 @@ Switch($Authtype)
5657
{
5758
#Set to AdminAccount or not set(old info file)
5859
{($_ -eq "AdminAccount") -or ($_ -eq $null)}{
60+
if($TenantId2){#Use TenantID if one was provided
61+
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2 -Tenant $TenantId2
62+
}
63+
else{
5964
Add-AzureRmAccount -EnvironmentName $cloudName2 -Credential $Credential2
6065
}
66+
}
6167
#Using CertSPN
6268
"CertSPN"{
6369
Add-AzureRmAccount -Environment $cloudName2 -ServicePrincipal -CertificateThumbprint $CertificateThumbprint2 -ApplicationId $ApplicationId2 -TenantId $TenantId2

asUsageToOMS.ps1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
[CmdletBinding()]
2-
param(
3-
[Parameter(Mandatory = $true)]
4-
[string] $CloudName
5-
)
6-
7-
Start-Transcript -Path "C:\AZSAdminOMSInt\asUsageToOMS_$CloudName.log"
8-
& .\usagesummaryjson.ps1 -CloudName $CloudName
9-
10-
# set execution policy and import OMS Ingestion API.
11-
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
12-
Install-Module -Name AzureRM.OperationalInsights -Force
13-
Install-Module -Name OMSIngestionAPI -Force
14-
15-
& .\uploadToOMS.ps1 -CloudName $CloudName
16-
exit
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string] $CloudName
5+
)
6+
7+
Start-Transcript -Path "C:\AZSAdminOMSInt\asUsageToOMS_$CloudName.log"
8+
& .\usagesummaryjson.ps1 -CloudName $CloudName
9+
10+
# set execution policy and import OMS Ingestion API.
11+
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
12+
Install-Module -Name AzureRM.OperationalInsights -Force
13+
Install-Module -Name OMSIngestionAPI -Force
14+
15+
& .\uploadToOMS.ps1 -CloudName $CloudName
16+
exit

docs/setup.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ The following are required to setup the environment. You should gather these var
4444
1. Access the privileged endpoint
4545
2. Run Get-AzureStackStampInformation
4646
3. Find and copy the deploymentguid from the output
47-
#### azureStackAdminUsername ="<e.g. Serviceadmin@myazurestackinstance.onmicrosoft.com>"
48-
1. Update with the Azure Stack Service Admin account email
49-
#### azureStackAdminPassword = "<e.g. MyAzureStackPassword206!>"
50-
1. Update with the Azure Stack Service Admin account password
5147
#### CloudName ="<e.g. Orlando MTC>"
5248
1. Update location with the name of your Cloud, this is how most data will pivot in the views
5349
#### Region = "<e.g. Orlando>"
@@ -60,6 +56,16 @@ The following are required to setup the environment. You should gather these var
6056
1. Update with the OMS/Log Analytics Workspace Primary Key found in the Advanced Settings pane of your Log Analytics workspace
6157
#### OEM = "<replace with your hardware vendor name>"
6258
1. Update with the name of your hardware vendor. Allows for reports in log analytics utilizing the OEM name.
59+
#### TenantId = "<replace with your TenantID>"
60+
1. Update with the TenantID, this is an optional parameter unless using SPN
61+
#### CertificateThumbprint = "<replace with thumbprint of cert setup for SPN>"
62+
1. If using a cert for SPN, update with the certs thumbprint. Optional parameter in place if AzureStackAdmin
63+
#### ApplicationId = "<Application ID for SPN>"
64+
1. If using cert for SPN, update with the ApplicationID that was setup for the SPN. Optional parameter in place if AzureStackAdmin
65+
#### azureStackAdminUsername ="<e.g. Serviceadmin@myazurestackinstance.onmicrosoft.com>"
66+
1. Update with the Azure Stack Service Admin account email
67+
#### azureStackAdminPassword = "<e.g. MyAzureStackPassword206!>"
68+
1. Update with the Azure Stack Service Admin account password
6369

6470
### Step 4 – Update variables
6571
1. Open an elevated PowerShell ISE session

0 commit comments

Comments
 (0)