PublishModuleIM.ps1

<#
.SYNOPSIS
This script is used in an ADO RM pipeline for releasing CrossTenantIdentityMapping PS module to PS gallery.
#>

<#
.PARAMETER NugetApiKey
API key to use for publishing the module
.PARAMETER ModulePath
Path to the folder where the module package is located.
.PARAMETER UpdatePowershellGet
Switch that specifies whether PowerShellGet should be updated to the latest version before publishing the module.
#>

param(
    [string] [Parameter(Mandatory=$true)] $NugetApiKey,
    [string] [Parameter(Mandatory=$true)] $ModulePath,
    [bool] [Parameter(Mandatory=$false)] $UpdatePowershellGet = $true
)

if ($UpdatePowershellGet)
{
    Write-Host "Installing PowerShellGet latest version"

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    [Net.ServicePointManager]::SecurityProtocol
    
    Write-Host "Updating Package provider..."
    Install-PackageProvider Nuget -Confirm:$false -Force -Scope CurrentUser
    
    Write-Host "Installing latest PowerShellGet module..."
    Install-Module PowerShellGet -AllowClobber -Confirm:$false -Force -Scope CurrentUser
    
    Write-Host "Installed module. Importing PowerShellGet module..."
    Import-Module PowerShellGet -Force
    
    Write-Host "Confirming version for PowershellGet..."
    Get-Module PowershellGet
    Write-Host "Successfully installed latest PowerShellGet..."    
}

Write-Host $PSScriptRoot
Write-Host 'Publishing CrossTenantIdentityMapping module package located at $ModulePath'
gci $ModulePath -Recurse
Publish-Module -NuGetApiKey $NuGetApiKey -Path $ModulePath -Verbose -Force
Write-Host 'Publish Complete.'