InstallLogetoModule.ps1
Function Write-LogetoProgress([String] $text, [String] $code) { if (Get-Command -CommandType Function -Name "Write-InstallerProgress" -ErrorAction SilentlyContinue) { Write-InstallerProgress $text $code } else { Write-Host $text } } Function Write-LogetoDebug([String] $text) { if (Get-Command -CommandType Function -Name "Write-InstallerDebug" -ErrorAction SilentlyContinue) { Write-InstallerDebug $text } else { Write-Host $text } } Function InstallLogetoModule() { try { if (!(Get-PSRepository -Name "PSGallery")) { Write-LogetoDebug "PSGallery is being registered." Register-PSRepository -Default -Verbose } Write-LogetoDebug "Getting NuGet package provider." if (!(Find-PackageProvider -Name "NuGet" -ForceBootstrap -Force)) { Get-PackageProvider -Name "NuGet" -ForceBootstrap -Force -Verbose } if (Get-Module -ListAvailable -Name Logeto) { Write-LogetoDebug "Updating Logeto Powershell Module." try { $local = Get-InstalledModule -AllVersions -Name "Logeto" if ($local.Count -gt 1) { Write-LogetoDebug "Remove old version of module." $Latest = Get-InstalledModule "Logeto" Get-InstalledModule "Logeto" -AllVersions | ? {$_.Version -ne $Latest.Version} | Uninstall-Module } $local = Get-InstalledModule -AllVersions -Name "Logeto" $online = Find-Module -Name "Logeto" if ($online.version -gt $local.version) { Write-LogetoDebug "Newer version was found." Update-Module -Name "Logeto" -Force -Verbose Write-LogetoDebug "Remove old version of module." $Latest = Get-InstalledModule "Logeto" Get-InstalledModule "Logeto" -AllVersions | ? {$_.Version -ne $Latest.Version} | Uninstall-Module } else { Write-LogetoDebug "No newer update for module was found." } } catch { Write-LogetoDebug "Updating module failed with reason ($_)" Update-Module -Name "Logeto" -Force -Verbose } } else { Write-LogetoDebug "Installing Logeto Powershell Module." Install-Module -Name "Logeto" -Scope CurrentUser -Force -SkipPublisherCheck -Verbose } } catch { Write-LogetoDebug "Logeto Powershell module could not been installed/updated ($_)" throw $_ } } Write-LogetoProgress "Installing Logeto module" "ScriptInstallLogetoModule" InstallLogetoModule; |