|
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 |
0 commit comments