MSPToolBox.psm1
[CmdletBinding()] #region discover module name $ScriptPath = Split-Path $MyInvocation.MyCommand.Path $ModuleName = $ExecutionContext.SessionState.Module Write-Verbose "Loading module $ModuleName" #endregion discover module name #load variables for module Write-Verbose "Creating modules variables" $mspToolBoxData = @{ ApplicationID = $null ApplicationSecret = $null Refreshtoken = $null TenantID = $null GraphAuthHeader = $null CustomerAuthHeader = $null ConnectedTenant = $null } $script:mspToolBoxSession = $mspToolBoxData #end of variables #load functions try { foreach ($Scope in 'Public', 'Private') { Get-ChildItem (Join-Path -Path $ScriptPath -ChildPath $Scope) -Recurse -Filter "func_*.ps1" | ForEach-Object { . $_.FullName if ($Scope -eq 'Public') { Export-ModuleMember -Function ($_.BaseName -Split "_")[1] -ErrorAction Stop } } } $module = Get-Module -ListAvailable PartnerCenter $minVer = "3.0.10" if ($module.version -ge [version]$minver) { Import-Module PartnerCenter -MinimumVersion $minVer -Force -Global } elseif ($module.version -lt [version]$minVer) { try { Update-Module PartnerCenter -Force Import-Module PartnerCenter -MinimumVersion $minVer -Force -Global } catch { throw "Failed to update 'PartnerCenter': {0}" -f $_.Exception.Message } } else { try { Install-Module PartnerCenter -MinimumVersion $minver Import-Module PartnerCenter -MinimumVersion $minVer -Force -Global } catch { throw "Module 'PartnerCenter' is not present, tried installing but raised an error: {0}" -f $_.Exception.Message } } } catch { Write-Error ("{0}: {1}" -f $_.BaseName, $_.Exception.Message) exit 1 } |