diff --git a/Install-EmberkomCloudBackup.ps1 b/Install-EmberkomCloudBackup.ps1 index 0ab956b..5940b38 100644 --- a/Install-EmberkomCloudBackup.ps1 +++ b/Install-EmberkomCloudBackup.ps1 @@ -15,10 +15,11 @@ switch ( $Edition.ToLower() ) { default { $URL = $ECB_WIN_URL; $AgentEdition = 'desktop' } } -## Install and import the MSP360 Powershell module -Run-Script -LivePSScript Install-MSP360PowershellModule -LogMsg "Importing MSP360 Powershell module" +## Install and import additional Powershell modules +Install-MSP360Module Import-Module -Name MSP360 +Install-PSAteraModule +Import-Module -Name PSAtera ## Install the agent $INSTALLER = Download-File -URL $URL @@ -36,15 +37,10 @@ LogMsg "Setting Emberkom Cloud Backup agent edition to ""$AgentEdition""" Try { Set-MBSAgentSetting -Edition $AgentEdition } Catch { $_.Exception.Message } -## Install and import the PSAtera Powershell Module -Run-Script -LivePSScript Install-PSAteraModule -LogMsg "Importing PSAtera Powershell module" -Import-Module -Name PSAtera -Set-AteraAPIKey = $AteraAPIKey - ## Get agent details and custom fields from Atera Try { LogMsg "Getting Atera agent and custom field information" + Set-AteraAPIKey = $AteraAPIKey $AteraAgent = Get-AteraAgent $MSP360Username = Get-AteraCustomValue -ObjectType Customer -ObjectId $AteraAgent.CustomerID -FieldName 'MSP360 Account Username' $MSP360Password = Get-AteraCustomValue -ObjectType Customer -ObjectId $AteraAgent.CustomerID -FieldName 'MSP360 Account Password' diff --git a/Install-MSP360PowershellModule.ps1 b/Install-MSP360PowershellModule.ps1 deleted file mode 100644 index be69a7b..0000000 --- a/Install-MSP360PowershellModule.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -## Check if the MSP360 module needs to be installed -If (-not (Get-Module -ListAvailable -Name MSP360) ) { - - LogMsg "Setting Powershell Execution Policy to Unrestricted for this script" - Try { Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process } - Catch { LogErr $_.Exception.Message } - - LogMsg "Downloading and installing MSP360 Powershell module" - Try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://git.io/JUSAA'); Install-MSP360Module } - Catch { LogErr $_.Exception.Message } - -} Else { LogMsg "MSP360 Powershell module is already installed" } diff --git a/Install-PSAteraModule.ps1 b/Install-PSAteraModule.ps1 deleted file mode 100644 index c01938e..0000000 --- a/Install-PSAteraModule.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -## Define settings for PSAtera module -$PSAteraMinimumModuleVersion = '1.5.7' - -## Get the PSAtera module if it's installed -$module = (Get-Module -ListAvailable -Name PSAtera) - -## Install only if we're an admin -If ( IsAdmin ) { - - ## If the module is installed, check to make sure it's updated - If ( $module ) { - [version]$current = $module.Version - [version]$minimum = (Get-Version $Global:PSAteraMinimumModuleVersion) - If ( $current -lt $minimum ) { - LogMsg "Updating Powershell module PSAtera" - Try { Update-Module -Name PSAtera -Force } - Catch { LogErr $_.Exception.Message } - } - } - - ## If it's not already installed, install it - Else { - Try { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityPotocol -bor 3072 } - Catch { LogErr $_.Exception.Message } - - LogMsg "Installing NuGet package manager" - Try { Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force} - Catch { LogErr $_.Exception.Message } - - LogMsg "Installing Powershell module PSAtera" - Try { Install-Module -Name PSAtera -MinimumVersion $(Get-Version $PSAteraMinimumModuleVersion) -Force} - Catch { LogErr $_.Exception.Message } - } -} -ElseIf ( ($Global:InstallPSAteraModule) -and (-not ($module)) ) { - LogMsg "The PSAtera module needs to be installed, but the current security context is not sufficient to install it" -} \ No newline at end of file diff --git a/Tools.ps1 b/Tools.ps1 index 144da70..a6534e6 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -481,5 +481,40 @@ function Toggle-Log { Catch { LogMsg $_.Exception.Message } } +# Function to install the PSAtera Powershell module +function Install-PSAteraModule { + Try { + $module = Get-Module -ListAvailable -Name PSAtera + If ( (-not $module) -and (IsAdmin) ) { + LogMsg "Installing PSAtera Powershell module" + Install-Module -Name PSAtera -MinimumVersion 2.8.5.201 + } + ElseIf ( (-not $module) -and (-not (IsAdmin)) ) { + LogMsg "The PSAtera module needs to be installed, but the current security context is not sufficient to install it" + } + ElseIf ( ($module) -and (IsAdmin) ) { + LogMsg "Updating PSAtera Powershell module" + Update-Module -Name PSAtera -Force + } + } + Catch { LogErr $_.Exception.Message } +} + +# Function to install the MSP360 Powershell module +function Install-MSP360Module { + Try { + $module = Get-Module -ListAvailable -Name MSP360 + If ( (-not $module) -and (IsAdmin) ) { + LogMsg "Installing MSP360 Powershell module" + Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://git.io/JUSAA'); Install-MSP360Module + } + ElseIf ( (-not $module) -and (-not (IsAdmin)) ) { + LogMsg "The MSP360 Powershell module needs to be installed, but the current security context is not sufficient to install it" + } + } + Catch { LogErr $_.Exception.Message } +} + Setup-MSPDirectories Setup-LogFile \ No newline at end of file