-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterScript.ps1
97 lines (83 loc) · 3.49 KB
/
MasterScript.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<#
.Synopsis
The script that gets called by the ARM template when it deploys a custom script extension.
It sets up a scheduled task to upload usage data to OMS.
.DESCRIPTION
It Sets up git and download repository containing the necessary scripts, stores necessary
information onto the host and then sets up a windows scheduled task to upload usage data
daily.
.EXAMPLE
This script is meant to be called from an ARM template.
.\MasterScript `
-DeploymentGuid <deployment guid> `
-OMSWorkspaceID "myomsworkspaceGUID" `
-OMSSharedKey "myomssharedkeyGUID" `
-azureStackAdminUsername "[email protected]" `
-azureStackAdminPassword $Password `
-CloudName "Cloud#1" `
-Region "local" `
-Fqdn "azurestack.external"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $DeploymentGuid,
[Parameter(Mandatory = $true)]
[string] $OMSWorkspaceID,
[Parameter(Mandatory = $true)]
[string] $OMSSharedKey,
[Parameter(Mandatory = $true)]
[string] $azureStackAdminUsername,
[Parameter(Mandatory = $true)]
[string] $azureStackAdminPassword,
[Parameter(Mandatory = $true)]
[string] $CloudName,
[Parameter(Mandatory = $true)]
[string] $Region,
[Parameter(Mandatory = $true)]
[string] $Fqdn
)
$azureStackAdminPasswordSecureString = $azureStackAdminPassword | ConvertTo-SecureString -Force -AsPlainText
cd c:\
# install git
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# refresh the PATH to recognize "choco" command
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
choco install git.install -y
# refresh the PATH to recognize git
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
git clone "https://github.com/Azure-Samples/AzureStack-AdminPowerShell-OMSIntegration.git" C:\AZSAdminOMSInt
# installing powershell modules for azure stack.
# NuGet required for Set-PsRepository PSGallery.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PsRepository PSGallery -InstallationPolicy Trusted
Get-Module -ListAvailable | where-Object {$_.Name -like "Azure*"} | Uninstall-Module
Install-Module -Name AzureRm.BootStrapper -Force
Install-Module -Name AzureRm.Resources -Force
Install-Module -Name AzureStack -Force
Install-Module -Name AzureRM.AzureStackAdmin -Force
Install-Module -Name Azs.Infrastructureinsights.Admin -Force
Install-Module -Name Azs.Update.Admin -Force
Install-Module -Name Azs.Fabric.Admin -Force
# store data required by scheduled task in files.
$info = @{
DeploymentGuid = $DeploymentGuid;
CloudName = $CloudName;
Region = $Region;
Fqdn = $Fqdn;
OmsWorkspaceID = $OMSWorkspaceID;
OmsSharedKey = $OMSSharedKey;
AzureStackAdminUsername = $azureStackAdminUsername;
}
$infoJson = ConvertTo-Json $info
Set-Content -Path "C:\AZSAdminOMSInt\info.txt" -Value $infoJson
#store passwords in txt files.
$passwordText = $azureStackAdminPasswordSecureString | ConvertFrom-SecureString
Set-Content -Path "C:\AZSAdminOMSInt\azspassword.txt" -Value $passwordText
#Download Azure Stack Tools VNext
cd c:\AZSAdminOMSInt
invoke-webrequest https://github.com/Azure/AzureStack-Tools/archive/vnext.zip -OutFile vnext.zip
expand-archive vnext.zip -DestinationPath . -Force
# schedule windows scheduled task
cd C:\AZSAdminOMSInt
& .\schedule_usage_upload.ps1