Public/Install-Dependencies.ps1
Function Install-Dependencies { [CmdletBinding()] param ( [Parameter()] $Dependencies = @("ImportExcel") ) Foreach ($Module in $Dependencies) { $Current = $null $Installed = $null Try { $Current = Find-Module $Module $Installed = Get-InstalledModule -AllVersions $Module If ($null -eq $Installed) { Write-Verbose "$Module Module is not installed, Installing Now" Install-Module $Module -Force } ElseIf ($null -ne $Installed) { if ($Installed.Version -notcontains $Current.Version) { Write-Verbose "$Module Module is not current, Updating Now" Update-Module $Module -Force } else { Write-Verbose "$Module Module is already Installed and Current" } } } Catch { Write-Warning $_ Write-Verbose "Errors Detected, Forcing Uninstall and Reinstall" $Installed | Uninstall-Module -Force Install-Module $Module -Force } $FinalInstalled = Get-Installedmodule $Dependencies Foreach ($Entry in $FinalInstalled) { $Temp = Find-Module $Entry.Name Return [PSCustomObject]@{ CurrentVersion = $Temp.Version InstalledVersion = $Entry.Version Name = $Entry.Name Repository = $Entry.Repository } } } } |