CodeSigning/Invoke-SignFile.ps1

<#
 .Synopsis
  Signs an app file
 .Description
  Signs an app file with the provided code sign certificate
 .Parameter ContainerName
  Name of the container. Can be provided in the settings.sjon
 .Parameter FileName
  Path to the app file to be signed
 .Parameter pfxFile
  Path to the code sign certificate
 .Parameter pfxPassword
  Password for the code sign certificate
 .Example
  Invoke-SignFile -FileName "C:\test.app" -pfxFile "C:\pfx.pfx" -pfxPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force)
#>

function Invoke-SignFile
{
    Param(
        [Parameter(Mandatory=$false)]
        [string] $ContainerName,
        [Parameter(Mandatory=$true)]
        [string] $FileName,
        [Parameter(Mandatory=$true)]
        [securestring] $pfxFile,
        [Parameter(Mandatory=$true)]
        [securestring] $pfxPassword
    )

    if ($null -eq $ContainerName -or $ContainerName -eq "") {
        $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name')
    }

    # Copy file to container path
    $ContainerPath = (Join-Path (Join-Path "C:\ProgramData\NavContainerHelper\Extensions" $containerName) "my")
    $ContainerPath = (Join-Path $ContainerPath (Split-Path $FileName -Leaf))

    Copy-Item $FileName $ContainerPath -Force | Out-Null

    #Sign
    $unsecurepfxFile = ([System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pfxFile)))
    Sign-NavContainerApp -containerName $containerName -appFile $ContainerPath -pfxFile $unsecurePfxFile -pfxPassword $pfxPassword

    # Copy file back
    Copy-Item $ContainerPath $FileName -Force | Out-Null
    Remove-Item $ContainerPath -Force | Out-Null
}
Export-ModuleMember -Function Invoke-SignFile