Skip to content

Commit a160f5e

Browse files
authored
Support Multiple Azurestack's tasks on 1 server
Changing how the Tasks, Logs, Info.txt and Password.txt are created so multiple AZURESTACKs' tasks could be run from a single server. This relies on the value provided to CloudName when running MasterScript to be unique on that server. Old Tasks will need to be recreated to function with the new scripts.
1 parent b12cb8d commit a160f5e

6 files changed

Lines changed: 49 additions & 19 deletions

File tree

MasterScript.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ $info = @{
8888
}
8989

9090
$infoJson = ConvertTo-Json $info
91-
Set-Content -Path "C:\AZSAdminOMSInt\info.txt" -Value $infoJson
91+
Set-Content -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" -Value $infoJson
9292

9393
#store passwords in txt files.
9494
$passwordText = $azureStackAdminPasswordSecureString | ConvertFrom-SecureString
95-
Set-Content -Path "C:\AZSAdminOMSInt\azspassword.txt" -Value $passwordText
95+
Set-Content -Path "C:\AZSAdminOMSInt\azspassword_$CloudName.txt" -Value $passwordText
9696

9797

9898
#Download Azure Stack Tools VNext
@@ -102,4 +102,4 @@ expand-archive vnext.zip -DestinationPath . -Force
102102

103103
# schedule windows scheduled task
104104
cd C:\AZSAdminOMSInt
105-
& .\schedule_usage_upload.ps1
105+
& .\schedule_usage_upload.ps1 -CloudName $CloudName

OpsDataToOMS.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Start-Transcript -Path C:\AZSAdminOMSInt\OpsDataToOMS.log
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string] $CloudName
5+
)
6+
7+
Start-Transcript -Path "C:\AZSAdminOMSInt\OpsDataToOMS_$CloudName.log"
28
Set-ExecutionPolicy Bypass -Force
39
Install-Module -Name OMSIngestionAPI -Force
410
Install-Module -Name AzureRM.OperationalInsights -Force
@@ -9,7 +15,7 @@ Import-Module -Name Azs.Fabric.Admin -Force
915

1016
#OMS Authentication Variables
1117

12-
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info.txt" | ConvertFrom-Json
18+
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" | ConvertFrom-Json
1319
$OMSWorkspaceId = $info.OmsWorkspaceID
1420
$OMSSharedKey = $info.OmsSharedKey
1521

@@ -19,7 +25,7 @@ $Location2 = $info.Region
1925
$cloudName2 = $info.CloudName
2026
$State2 = "active"
2127
$UserName2= $info.AzureStackAdminUsername
22-
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword.txt"| ConvertTo-SecureString
28+
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
2329
$Credential2=New-Object PSCredential($UserName2,$Password2)
2430

2531
$deploymentGuid = $info.DeploymentGuid

asUsageToOMS.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
Start-Transcript -Path C:\AZSAdminOMSInt\asUsageToOMS.log
2-
& .\usagesummaryjson.ps1
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
39

410
# set execution policy and import OMS Ingestion API.
511
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
612
Install-Module -Name AzureRM.OperationalInsights -Force
713
Install-Module -Name OMSIngestionAPI -Force
814

9-
& .\uploadToOMS.ps1
15+
& .\uploadToOMS.ps1 -CloudName $CloudName
1016
exit

schedule_usage_upload.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string] $CloudName
5+
)
6+
17
#Usage Data Upload
28
$action = New-ScheduledTaskAction -Execute 'Powershell' `
3-
-Argument '.\asUsageToOMS.ps1' -WorkingDirectory "C:\AZSAdminOMSInt"
9+
-Argument (".\asUsageToOMS.ps1 -CloudName '{0}'" -f $CloudName) -WorkingDirectory "C:\AZSAdminOMSInt"
410
$description = "Daily upload of usage data from azure stack to OMS"
5-
$taskName = "UsageDataUpload1"
11+
$taskName = "UsageDataUpload1_$CloudName"
612

713
$trigger = New-ScheduledTaskTrigger -Daily -At 9am
814
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM"
@@ -14,9 +20,9 @@ Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Pr
1420

1521
#Operational Data Upload
1622
$action = New-ScheduledTaskAction -Execute 'Powershell' `
17-
-Argument '.\OpsDataToOMS.ps1' -WorkingDirectory "C:\AZSAdminOMSInt"
23+
-Argument (".\OpsDataToOMS.ps1 -CloudName '{0}'" -f $CloudName) -WorkingDirectory "C:\AZSAdminOMSInt"
1824
$description = "Daily upload of operational data from azure stack to OMS"
19-
$taskName = "OperationalDataUpload1"
25+
$taskName = "OperationalDataUpload1_$CloudName"
2026

2127
$trigger = New-ScheduledTaskTrigger -once -at (Get-date) -RepetitionInterval (New-TimeSpan -Minutes 13) -RepetitionDuration (New-TimeSpan -Days 9999)
2228
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM"

uploadToOMS.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Start-Transcript -Path C:\AZSAdminOMSInt\uploadtoOMS.log
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string] $CloudName
5+
)
6+
7+
Start-Transcript -Path "C:\AZSAdminOMSInt\uploadtoOMS_$CloudName.log"
28
Set-ExecutionPolicy Bypass -Force
39
Install-Module -Name OMSIngestionAPI -Force
410
Install-Module -Name AzureRM.OperationalInsights -Force
@@ -9,7 +15,7 @@ Import-Module -Name Azs.Fabric.Admin -Force
915

1016
#OMS Authentication Variables
1117

12-
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info.txt" | ConvertFrom-Json
18+
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" | ConvertFrom-Json
1319
$OMSWorkspaceId = $info.OmsWorkspaceID
1420
$OMSSharedKey = $info.OmsSharedKey
1521

@@ -18,7 +24,7 @@ $Location2 = $info.Region
1824
$cloudName2 = $info.CloudName
1925
$State2 = "active"
2026
$UserName2= $info.AzureStackAdminUsername
21-
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword.txt"| ConvertTo-SecureString
27+
$Password2= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
2228
$Credential2=New-Object PSCredential($UserName2,$Password2)
2329

2430
$deploymentGuid = $info.DeploymentGuid

usagesummaryjson.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
.EXAMPLE
99
Export-AzureStackUsage -StartTime 2/15/2017 -EndTime 2/16/2017 -AzureStackDomain azurestack.local -AADDomain mydir.onmicrosoft.com -Granularity Hourly
1010
#>
11-
Start-Transcript -Path C:\AZSAdminOMSInt\usagesummaryjson.log
11+
[CmdletBinding()]
12+
param(
13+
[Parameter(Mandatory = $true)]
14+
[string] $CloudName
15+
)
16+
17+
Start-Transcript -Path "C:\AZSAdminOMSInt\usagesummaryjson_$CloudName.log"
1218

1319
function Export-AzureStackUsage {
1420
Param
@@ -194,9 +200,9 @@ $dayBeforeYesterday = $yesterday.addDays(-1)
194200
$usageStartTime = $dayBeforeYesterday.ToShortDateString()
195201
$usageEndTime = $yesterday.ToShortDateString()
196202

197-
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info.txt" | ConvertFrom-Json
203+
$info = Get-Content -Raw -Path "C:\AZSAdminOMSInt\info_$CloudName.txt" | ConvertFrom-Json
198204
$Username = $info.AzureStackAdminUsername
199-
$Password= Get-Content "C:\AZSAdminOMSInt\azspassword.txt"| ConvertTo-SecureString
205+
$Password= Get-Content "C:\AZSAdminOMSInt\azspassword_$CloudName.txt"| ConvertTo-SecureString
200206
$aadCred = New-Object PSCredential($Username, $Password)
201207
$cloudName2 = $info.CloudName
202208
$Location2 = $info.Region

0 commit comments

Comments
 (0)