From dd7dcc0010872af0280faa57988218c2e33b70aa Mon Sep 17 00:00:00 2001 From: Peppe Kerstens Date: Tue, 30 Jul 2019 09:30:23 +0200 Subject: [PATCH 1/5] fixes #54 --- Utility/ARM/New-OnPremiseHybridWorker.ps1 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Utility/ARM/New-OnPremiseHybridWorker.ps1 b/Utility/ARM/New-OnPremiseHybridWorker.ps1 index 095e564..5fe908e 100644 --- a/Utility/ARM/New-OnPremiseHybridWorker.ps1 +++ b/Utility/ARM/New-OnPremiseHybridWorker.ps1 @@ -1,6 +1,6 @@ <#PSScriptInfo -.VERSION 1.6 +.VERSION 1.7 .GUID b6ad1d8e-263a-46d6-882b-71592d6e166d @@ -26,6 +26,10 @@ .RELEASENOTES +1.7 - 7/30/2019 + -- MODIFIED BY Peppe Kerstens + -- #54 Fixed source assumption. + 1.6 - 11/15/2018 -- MODIFIED BY Alexander Zabielski -- Updated the parameters to accept a TenantID to pass to the connection params. @@ -136,9 +140,9 @@ AUTHOR: Jenny Hunter, Azure Automation Team - LASTEDIT: May 29, 2018 + LASTEDIT: July 30 2019 - EDITBY: Jenny Hunter + EDITBY: Peppe Kerstens #> @@ -184,13 +188,16 @@ $ErrorActionPreference = "Stop" Write-Output "Importing necessary modules..." # Create a list of the modules necessary to register a hybrid worker -$AzureRmModule = @{"Name" = "AzureRM"; "Version" = ""} +$AzureRmModule = @{"Name" = "AzureRM"; "Version" = ""; "Repository" = "PSGallery"} $Modules = @($AzureRmModule) # Import modules foreach ($Module in $Modules) { $ModuleName = $Module.Name + $splatRepository = @{} + If ($Module.Repository) {$splatRepository.Repository = $Module.Repository} + # Find the module version if ([string]::IsNullOrEmpty($Module.Version)){ @@ -205,11 +212,11 @@ foreach ($Module in $Modules) { } # Check if the required module is already installed - $CurrentModule = Get-Module -Name $ModuleName -ListAvailable | where "Version" -eq $ModuleVersion + $CurrentModule = Get-Module -Name $ModuleName -ListAvailable | Where-Object "Version" -eq $ModuleVersion if (!$CurrentModule) { - $null = Install-Module -Name $ModuleName -RequiredVersion $ModuleVersion -Force + $null = Install-Module -Name $ModuleName -RequiredVersion $ModuleVersion @splatRepository -Force Write-Output " Successfully installed version $ModuleVersion of $ModuleName..." } else { From bf4e883215185f62c0ffdc3a8f3bd15511ae232c Mon Sep 17 00:00:00 2001 From: Peppe Kerstens Date: Tue, 30 Jul 2019 09:42:51 +0200 Subject: [PATCH 2/5] Proper PS command, no aliases --- Utility/ARM/New-OnPremiseHybridWorker.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Utility/ARM/New-OnPremiseHybridWorker.ps1 b/Utility/ARM/New-OnPremiseHybridWorker.ps1 index 5fe908e..1c09ecd 100644 --- a/Utility/ARM/New-OnPremiseHybridWorker.ps1 +++ b/Utility/ARM/New-OnPremiseHybridWorker.ps1 @@ -349,7 +349,7 @@ try { $null = Unblock-File $Destination # Change directory to location of the downloaded MMA - cd $env:temp + Set-Location -Path $env:temp # Install the MMA $Command = "/C:setup.exe /qn ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=$WorkspaceID" + " OPINSIGHTS_WORKSPACE_KEY=$WorkspaceKey " + " AcceptEndUserLicenseAgreement=1" @@ -368,9 +368,9 @@ do { # Check for the MMA folders try { # Change the directory to the location of the hybrid registration module - cd "$env:ProgramFiles\Microsoft Monitoring Agent\Agent\AzureAutomation" - $version = (ls | Sort-Object LastWriteTime -Descending | Select -First 1).Name - cd "$version\HybridRegistration" + Set-Location -Path "$env:ProgramFiles\Microsoft Monitoring Agent\Agent\AzureAutomation" + $version = (Get-ChildItem | Sort-Object LastWriteTime -Descending | Select-Item -First 1).Name + Set-Location -Path "$version\HybridRegistration" # Import the module Import-Module (Resolve-Path('HybridRegistration.psd1')) From adb9f7b04c3ae6f5774498d6f841fb10ab7e87f8 Mon Sep 17 00:00:00 2001 From: Peppe Kerstens Date: Tue, 30 Jul 2019 09:50:56 +0200 Subject: [PATCH 3/5] Proper PS command, no aliases --- Utility/ARM/New-OnPremiseHybridWorker.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Utility/ARM/New-OnPremiseHybridWorker.ps1 b/Utility/ARM/New-OnPremiseHybridWorker.ps1 index 5fe908e..259eaed 100644 --- a/Utility/ARM/New-OnPremiseHybridWorker.ps1 +++ b/Utility/ARM/New-OnPremiseHybridWorker.ps1 @@ -29,6 +29,7 @@ 1.7 - 7/30/2019 -- MODIFIED BY Peppe Kerstens -- #54 Fixed source assumption. + -- removed aliases, proper PS commands 1.6 - 11/15/2018 -- MODIFIED BY Alexander Zabielski @@ -349,7 +350,7 @@ try { $null = Unblock-File $Destination # Change directory to location of the downloaded MMA - cd $env:temp + Set-Location -Path $env:temp # Install the MMA $Command = "/C:setup.exe /qn ADD_OPINSIGHTS_WORKSPACE=1 OPINSIGHTS_WORKSPACE_ID=$WorkspaceID" + " OPINSIGHTS_WORKSPACE_KEY=$WorkspaceKey " + " AcceptEndUserLicenseAgreement=1" @@ -368,9 +369,9 @@ do { # Check for the MMA folders try { # Change the directory to the location of the hybrid registration module - cd "$env:ProgramFiles\Microsoft Monitoring Agent\Agent\AzureAutomation" - $version = (ls | Sort-Object LastWriteTime -Descending | Select -First 1).Name - cd "$version\HybridRegistration" + Set-Location -Path "$env:ProgramFiles\Microsoft Monitoring Agent\Agent\AzureAutomation" + $version = (Get-ChildItem | Sort-Object LastWriteTime -Descending | Select-Item -First 1).Name + Set-Location -Path "$version\HybridRegistration" # Import the module Import-Module (Resolve-Path('HybridRegistration.psd1')) From c4bbed6ee0ab6481de256f34f1e12f3f252c74bc Mon Sep 17 00:00:00 2001 From: Peppe Kerstens Date: Tue, 30 Jul 2019 09:51:47 +0200 Subject: [PATCH 4/5] fixes #51 (already fixed without reference) --- Utility/ARM/New-OnPremiseHybridWorker.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utility/ARM/New-OnPremiseHybridWorker.ps1 b/Utility/ARM/New-OnPremiseHybridWorker.ps1 index 259eaed..9c333eb 100644 --- a/Utility/ARM/New-OnPremiseHybridWorker.ps1 +++ b/Utility/ARM/New-OnPremiseHybridWorker.ps1 @@ -253,7 +253,7 @@ $Account = Add-AzureRmAccount @paramsplat # Set the active subscription $null = Set-AzureRmContext -SubscriptionID $SubscriptionID -# Check that the resource groups are valid +# Check that the resource groups are valid $null = Get-AzureRmResourceGroup -Name $AAResourceGroupName if ($OMSResourceGroupName) { $null = Get-AzureRmResourceGroup -Name $OMSResourceGroupName From 08ef514649c8766fc2c59a2c53788fdb15805a48 Mon Sep 17 00:00:00 2001 From: Peppe Kerstens Date: Tue, 30 Jul 2019 10:03:26 +0200 Subject: [PATCH 5/5] #49 added Az check by rcarboneras --- Utility/ARM/New-OnPremiseHybridWorker.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Utility/ARM/New-OnPremiseHybridWorker.ps1 b/Utility/ARM/New-OnPremiseHybridWorker.ps1 index 9c333eb..bbc4a25 100644 --- a/Utility/ARM/New-OnPremiseHybridWorker.ps1 +++ b/Utility/ARM/New-OnPremiseHybridWorker.ps1 @@ -30,6 +30,7 @@ -- MODIFIED BY Peppe Kerstens -- #54 Fixed source assumption. -- removed aliases, proper PS commands + -- #49 added Az check as implemented by rcarboneras to overcome merge conflicts 1.6 - 11/15/2018 -- MODIFIED BY Alexander Zabielski @@ -220,6 +221,15 @@ foreach ($Module in $Modules) { $null = Install-Module -Name $ModuleName -RequiredVersion $ModuleVersion @splatRepository -Force Write-Output " Successfully installed version $ModuleVersion of $ModuleName..." + } else { + if (($ModuleName -eq "AzureRm") -and (Get-InstalledModule -Name Az)) { + Write-Output "$ModuleName was not found but Az module is installed instead. Enabling ARM Aliases.." + Enable-AzureRmAlias + } else { + + $null = Install-Module -Name $ModuleName -RequiredVersion $ModuleVersion -Force + Write-Output " Successfully installed version $ModuleVersion of $ModuleName..." + } } else { Write-Output " Required version $ModuleVersion of $ModuleName is installed..." }