Skip to content

Commit 25c9873

Browse files
authored
Fix PowerShell lint warnings (#1463)
1 parent 320d45d commit 25c9873

File tree

93 files changed

+2248
-2114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2248
-2114
lines changed

src/optimization-engine/Deploy-AzureOptimizationEngine.ps1

Lines changed: 344 additions & 253 deletions
Large diffs are not rendered by default.

src/optimization-engine/Register-MultitenantAutomationSchedules.ps1

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,34 @@ Register-MultitenantAutomationSchedules.ps1 -AutomationAccountName "AOE" -Resour
4646
https://aka.ms/AzureOptimizationEngine/customize
4747
#>
4848
param(
49-
[Parameter(Mandatory = $false)]
49+
[Parameter(Mandatory = $false)]
5050
[String] $AzureEnvironment = "AzureCloud",
5151

52-
[Parameter(Mandatory = $true)]
52+
[Parameter(Mandatory = $true)]
5353
[String] $AutomationAccountName,
5454

55-
[Parameter(Mandatory = $true)]
55+
[Parameter(Mandatory = $true)]
5656
[String] $ResourceGroupName,
5757

58-
[Parameter(Mandatory = $true)]
58+
[Parameter(Mandatory = $true)]
5959
[String] $TargetSchedulesSuffix,
6060

61-
[Parameter(Mandatory = $false)]
61+
[Parameter(Mandatory = $false)]
6262
[int] $TargetSchedulesOffsetMinutes = 0,
6363

64-
[Parameter(Mandatory = $false)]
64+
[Parameter(Mandatory = $false)]
6565
[String] $TargetAzureEnvironment = "AzureCloud",
6666

67-
[Parameter(Mandatory = $true)]
67+
[Parameter(Mandatory = $true)]
6868
[String] $TargetTenantId,
6969

70-
[Parameter(Mandatory = $true)]
70+
[Parameter(Mandatory = $true)]
7171
[String] $TargetTenantCredentialName,
7272

73-
[Parameter(Mandatory = $false)]
73+
[Parameter(Mandatory = $false)]
7474
[String[]] $ExcludedRunbooks = @("Export-ReservationsPriceToBlobStorage","Export-PriceSheetToBlobStorage","Export-ReservationsUsageToBlobStorage","Export-SavingsPlansUsageToBlobStorage"),
7575

76-
[Parameter(Mandatory = $false)]
76+
[Parameter(Mandatory = $false)]
7777
[String[]] $IncludedRunbooks = @()
7878
)
7979

@@ -98,7 +98,7 @@ try
9898
}
9999
catch
100100
{
101-
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
101+
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
102102
}
103103

104104
$dataCollectionRunbooks = $scheduledRunbooks | Where-Object { $_.RunbookName -like "Export-*" -and $_.RunbookName -notin $ExcludedRunbooks -and $_.RunbookName -ne "Export-ReservationsPriceToBlobStorage" }

src/optimization-engine/Reset-AutomationSchedules.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ The name of the Resource Group where the Automation Account is located.
2121
https://aka.ms/AzureOptimizationEngine/customize
2222
#>
2323
param(
24-
[Parameter(Mandatory = $false)]
24+
[Parameter(Mandatory = $false)]
2525
[String] $AzureEnvironment = "AzureCloud",
2626

27-
[Parameter(Mandatory = $true)]
27+
[Parameter(Mandatory = $true)]
2828
[String] $AutomationAccountName,
2929

30-
[Parameter(Mandatory = $true)]
30+
[Parameter(Mandatory = $true)]
3131
[String] $ResourceGroupName
3232
)
3333

@@ -50,7 +50,7 @@ try {
5050
$scheduledRunbooks = Get-AzAutomationScheduledRunbook -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
5151
}
5252
catch {
53-
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
53+
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
5454
}
5555

5656
if (-not($scheduledRunbooks)) {
@@ -115,7 +115,7 @@ if ($newBaseTimeStr -ne $baseTimeStr) {
115115
{
116116
$newStartTime = $newStartTime.AddDays(1)
117117
}
118-
$newStartTime = $newStartTime.Add([System.Xml.XmlConvert]::ToTimeSpan($manifestSchedule.offset))
118+
$newStartTime = $newStartTime.Add([System.Xml.XmlConvert]::ToTimeSpan($manifestSchedule.offset))
119119
}
120120
$expiryTime = $schedule.ExpiryTime.ToString("yyyy-MM-ddTHH:mm:ssZ")
121121
$startTime = $newStartTime.ToString("yyyy-MM-ddTHH:mm:ssZ")
@@ -131,7 +131,7 @@ if ($newBaseTimeStr -ne $baseTimeStr) {
131131
`"advancedSchedule`": {}
132132
}
133133
}"
134-
Invoke-AzRestMethod -Path $automationPath -Method PUT -Payload $body | Out-Null
134+
Invoke-AzRestMethod -Path $automationPath -Method PUT -Payload $body | Out-Null
135135
Write-Host "Re-scheduled $($schedule.Name)." -ForegroundColor Blue
136136
}
137137
else {
@@ -141,7 +141,7 @@ if ($newBaseTimeStr -ne $baseTimeStr) {
141141
}
142142
else
143143
{
144-
throw "Interrupting schedules reset due to user input."
144+
throw "Interrupting schedules reset due to user input."
145145
}
146146
}
147147
else {
@@ -170,10 +170,10 @@ if ($newHybridWorker)
170170
$hybridWorker = Get-AzAutomationHybridWorkerGroup -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -Name $newHybridWorker -ErrorAction SilentlyContinue
171171
if (-not($hybridWorker))
172172
{
173-
throw "Hybrid Worker $newHybridWorker was not found in Automation Account $automationAccountName."
173+
throw "Hybrid Worker $newHybridWorker was not found in Automation Account $automationAccountName."
174174
}
175175

176-
Write-Host "Updating Hybrid Worker Group in every runbook schedule to $newHybridWorker..."
176+
Write-Host "Updating Hybrid Worker Group in every runbook schedule to $newHybridWorker..."
177177
$continueInput = Read-Host "Continue (Y/N)?"
178178

179179
if ("Y", "y" -contains $continueInput)
@@ -188,16 +188,16 @@ if ($newHybridWorker)
188188
$params = @{}
189189
$jobSchedule.properties.parameters.PSObject.Properties | ForEach-Object {
190190
$params[$_.Name] = $_.Value
191-
}
191+
}
192192
Register-AzAutomationScheduledRunbook -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName `
193193
-RunbookName $jobSchedule.properties.runbook.name -ScheduleName $jobSchedule.properties.schedule.name -RunOn $newHybridWorker -Parameters $params | Out-Null
194194
Write-Host "Re-registered $($jobSchedule.properties.runbook.name) for schedule $($jobSchedule.properties.schedule.name)." -ForegroundColor Blue
195195
}
196-
}
196+
}
197197
}
198198
else
199199
{
200-
throw "Interrupting schedules reset due to user input."
200+
throw "Interrupting schedules reset due to user input."
201201
}
202202
}
203203
else

src/optimization-engine/Setup-BenefitsUsageDependencies.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
This script sets up the necessary dependencies for the Azure Optimization Engine to collect the data required for the several Azure benefits workbooks.
44
55
.DESCRIPTION
6-
This script sets up the necessary dependencies for the Azure Optimization Engine to collect the data required for the several Azure benefits workbooks.
7-
It will ask for the customer type (EA or MCA), the billing account ID, the billing profile ID (if MCA), and the consumption currency code. It will then grant
6+
This script sets up the necessary dependencies for the Azure Optimization Engine to collect the data required for the several Azure benefits workbooks.
7+
It will ask for the customer type (EA or MCA), the billing account ID, the billing profile ID (if MCA), and the consumption currency code. It will then grant
88
the necessary roles to the Azure Optimization Engine managed identity and set up the required variables in the Automation Account.
99
1010
.PARAMETER AzureEnvironment
@@ -23,13 +23,13 @@ The name of the Resource Group where the Automation Account is located.
2323
https://aka.ms/AzureOptimizationEngine/commitmentssetup
2424
#>
2525
param(
26-
[Parameter(Mandatory = $false)]
26+
[Parameter(Mandatory = $false)]
2727
[String] $AzureEnvironment = "AzureCloud",
2828

29-
[Parameter(Mandatory = $true)]
29+
[Parameter(Mandatory = $true)]
3030
[String] $AutomationAccountName,
3131

32-
[Parameter(Mandatory = $true)]
32+
[Parameter(Mandatory = $true)]
3333
[String] $ResourceGroupName
3434
)
3535

@@ -52,7 +52,7 @@ try {
5252
$scheduledRunbooks = Get-AzAutomationScheduledRunbook -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
5353
}
5454
catch {
55-
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
55+
throw "$AutomationAccountName Automation Account not found in Resource Group $ResourceGroupName in Subscription $($ctx.Subscription.Name). If we are not in the right subscription, use Set-AzContext to switch to the correct one."
5656
}
5757

5858
if (-not($scheduledRunbooks)) {
@@ -79,7 +79,7 @@ $mcaBillingProfileIdRegex = "([A-Za-z0-9]+(-[A-Za-z0-9]+)+)"
7979
$customerType = Read-Host "Are you an Enterprise Agreement (EA), Microsoft Customer Agreement (MCA), or other type (Other) of customer? Please, type EA, MCA, or Other"
8080

8181
switch ($customerType) {
82-
"EA" {
82+
"EA" {
8383
$billingAccountId = Read-Host "Please, enter your Enterprise Agreement Billing Account ID (e.g. 12345678)"
8484
try
8585
{
@@ -141,7 +141,7 @@ switch ($customerType) {
141141
if (-not($roleAssignmentResponse.StatusCode -in (200,201,202)))
142142
{
143143
throw "The Billing Profile Reader role could not be granted. Status Code: $($roleAssignmentResponse.StatusCode); Response: $($roleAssignmentResponse.Content)"
144-
}
144+
}
145145
}
146146
else
147147
{
@@ -178,7 +178,7 @@ if ($billingProfileId)
178178
else
179179
{
180180
Set-AzAutomationVariable -ResourceGroupName $ResourceGroupName -AutomationAccountName $AutomationAccountName -Name $billingProfileIdVarName -Value $billingProfileId -Encrypted $false | Out-Null
181-
}
181+
}
182182
}
183183

184184
$currencyCode = Read-Host "Please, enter your consumption currency code (e.g. EUR, USD, etc.)"

src/optimization-engine/Setup-DataCollectionRules.ps1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ The tags to apply to the resources created.
2525
https://aka.ms/AzureOptimizationEngine/customize
2626
#>
2727
param(
28-
[Parameter(Mandatory = $false)]
28+
[Parameter(Mandatory = $false)]
2929
[String] $AzureEnvironment = "AzureCloud",
3030

31-
[Parameter(Mandatory = $true)]
31+
[Parameter(Mandatory = $true)]
3232
[String] $DestinationWorkspaceResourceId,
3333

34-
[Parameter(Mandatory = $false)]
34+
[Parameter(Mandatory = $false)]
3535
[int] $IntervalSeconds = 60,
3636

3737
[Parameter(Mandatory = $false)]
@@ -56,7 +56,7 @@ else {
5656
$lastDeploymentStatePath = ".\last-deployment-state.json"
5757
$deploymentOptions = @{}
5858

59-
$perfCounters = Get-Content -Path ".\perfcounters.json" | ConvertFrom-Json
59+
$perfCounters = Get-Content -Path ".\perfcounters.json" | ConvertFrom-Json
6060

6161
if ((Test-Path -Path $lastDeploymentStatePath))
6262
{
@@ -68,7 +68,7 @@ if ((Test-Path -Path $lastDeploymentStatePath))
6868
foreach ($property in $depOptions.PSObject.Properties)
6969
{
7070
$deploymentOptions[$property.Name] = $property.Value
71-
}
71+
}
7272
}
7373
}
7474

@@ -82,7 +82,7 @@ if ($subscriptions.Count -gt 1) {
8282
{
8383
if (-not($deploymentOptions["SubscriptionId"]))
8484
{
85-
Write-Output "[$i] $($subscriptions[$i].Name)"
85+
Write-Output "[$i] $($subscriptions[$i].Name)"
8686
}
8787
else
8888
{
@@ -99,11 +99,11 @@ if ($subscriptions.Count -gt 1) {
9999
while ($selectedSubscription -lt 0 -or $selectedSubscription -gt $lastSubscriptionIndex) {
100100
Write-Output "---"
101101
$selectedSubscription = [int] (Read-Host "Please, select the target subscription for this deployment [0..$lastSubscriptionIndex]")
102-
}
102+
}
103103
}
104104
if ($selectedSubscription -eq -1)
105105
{
106-
throw "The selected subscription does not exist. Check if you are logged in with the right Microsoft Entra ID user."
106+
throw "The selected subscription does not exist. Check if you are logged in with the right Microsoft Entra ID user."
107107
}
108108
}
109109
else
@@ -145,7 +145,7 @@ if (-not($deploymentOptions["NamePrefix"]))
145145
{
146146
$namePrefix = "EmptyNamePrefix"
147147
}
148-
}
148+
}
149149
while ($namePrefix.Length -gt 21)
150150
}
151151
else {
@@ -155,7 +155,7 @@ else {
155155
}
156156
else
157157
{
158-
$namePrefix = $deploymentOptions["NamePrefix"]
158+
$namePrefix = $deploymentOptions["NamePrefix"]
159159
}
160160
}
161161

@@ -184,7 +184,7 @@ if ([string]::IsNullOrEmpty($namePrefix) -or $namePrefix -eq "EmptyNamePrefix")
184184
$linuxDcrName = Read-Host "Enter the Linux DCR name"
185185
}
186186
else {
187-
$windowsDcrName = $windowsDcrNameTemplate -f $namePrefix
187+
$windowsDcrName = $windowsDcrNameTemplate -f $namePrefix
188188
$linuxDcrName = $linuxDcrNameTemplate -f $namePrefix
189189
}
190190

@@ -193,26 +193,26 @@ if (-not($deploymentOptions["TargetLocation"]))
193193
if (-not($rg.Location)) {
194194
Write-Host "Getting Azure locations..." -ForegroundColor Green
195195
$locations = Get-AzLocation | Where-Object { $_.Providers -contains "Microsoft.Insights" } | Sort-Object -Property Location
196-
196+
197197
for ($i = 0; $i -lt $locations.Count; $i++) {
198-
Write-Output "[$i] $($locations[$i].location)"
198+
Write-Output "[$i] $($locations[$i].location)"
199199
}
200200
$selectedLocation = -1
201201
$lastLocationIndex = $locations.Count - 1
202202
while ($selectedLocation -lt 0 -or $selectedLocation -gt $lastLocationIndex) {
203203
Write-Output "---"
204204
$selectedLocation = [int] (Read-Host "Please, select the target location for this deployment [0..$lastLocationIndex]")
205205
}
206-
207-
$targetLocation = $locations[$selectedLocation].location
206+
207+
$targetLocation = $locations[$selectedLocation].location
208208
}
209209
else {
210-
$targetLocation = $rg.Location
210+
$targetLocation = $rg.Location
211211
}
212212
}
213213
else
214214
{
215-
$targetLocation = $deploymentOptions["TargetLocation"]
215+
$targetLocation = $deploymentOptions["TargetLocation"]
216216
}
217217

218218
$windowsPerfCounters = @()

src/optimization-engine/Setup-LogAnalyticsWorkspaces.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<#
22
.SYNOPSIS
3-
This script sets up Log Analytics workspaces for Azure Optimization Engine to collect the required performance counters with
3+
This script sets up Log Analytics workspaces for Azure Optimization Engine to collect the required performance counters with
44
the legacy Log Analytics agent (to be deprecated on Aug 31, 2024).
55
66
.DESCRIPTION
@@ -27,16 +27,16 @@ The interval in seconds to collect performance counters.
2727
https://aka.ms/AzureOptimizationEngine/customize
2828
#>
2929
param(
30-
[Parameter(Mandatory = $false)]
30+
[Parameter(Mandatory = $false)]
3131
[String] $AzureEnvironment = "AzureCloud",
3232

33-
[Parameter(Mandatory = $false)]
33+
[Parameter(Mandatory = $false)]
3434
[String[]] $WorkspaceIds,
3535

3636
[Parameter(Mandatory = $false)]
3737
[switch] $AutoFix,
3838

39-
[Parameter(Mandatory = $false)]
39+
[Parameter(Mandatory = $false)]
4040
[int] $IntervalSeconds = 60
4141
)
4242

@@ -65,7 +65,7 @@ if ($wsIds)
6565
$whereWsIds = " and properties.customerId in ($wsIds)"
6666
}
6767

68-
$perfCounters = Get-Content -Path ".\perfcounters.json" | ConvertFrom-Json
68+
$perfCounters = Get-Content -Path ".\perfcounters.json" | ConvertFrom-Json
6969

7070
$ARGPageSize = 1000
7171

@@ -86,7 +86,7 @@ foreach ($workspace in $workspaces) {
8686
if ($laQueryResults)
8787
{
8888
$results = [System.Linq.Enumerable]::ToArray($laQueryResults.Results)
89-
Write-Output "$($workspace.name) ($($workspace.properties.customerId)): $($results.AzureComputersCount) Azure computers connected."
89+
Write-Output "$($workspace.name) ($($workspace.properties.customerId)): $($results.AzureComputersCount) Azure computers connected."
9090
}
9191
else
9292
{
@@ -154,12 +154,12 @@ foreach ($workspace in $workspaces) {
154154
$missingObjectCounters = $missingLinuxCounters | Where-Object { $_.objectName -eq $linuxObject }
155155
$missingInstance = ($missingObjectCounters | Select-Object -Property instance -Unique -First 1).instance
156156
$missingCounterNames = ($missingObjectCounters).counterName
157-
157+
158158
Write-Output "Adding $linuxObject object..."
159159
New-AzOperationalInsightsLinuxPerformanceObjectDataSource -ResourceGroupName $workspace.resourceGroup -WorkspaceName $workspace.name `
160160
-Name "DataSource_LinuxPerformanceObject_$(New-Guid)" -ObjectName $linuxObject -InstanceName $missingInstance -IntervalSeconds $IntervalSeconds `
161161
-CounterNames $missingCounterNames -Force | Out-Null
162-
}
162+
}
163163
}
164164
}
165165
}

0 commit comments

Comments
 (0)