diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc0c9e5..3e51586 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,8 +35,14 @@ jobs: $cert = Import-PfxCertificate -FilePath ./cert.pfx -CertStoreLocation Cert:\LocalMachine\My -Password $Password Set-AuthenticodeSignature InstanceExport.ps1 $cert shell: pwsh + - name: Create Release + if: startsWith(github.ref, 'refs/tags/') + uses: ncipollo/release-action@v1 + with: + artifacts: ./InstanceExport/PowerShell/InstanceExport.ps1 + generateReleaseNotes: true - name: Publish artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.ARTIFACT_NAME }} - path: ./InstanceExport/PowerShell/InstanceExport.ps1 \ No newline at end of file + path: ./InstanceExport/PowerShell/InstanceExport.ps1 diff --git a/InstanceExport/PowerShell/InstanceExport.ps1 b/InstanceExport/PowerShell/InstanceExport.ps1 index ae3dda0..a5ff759 100644 --- a/InstanceExport/PowerShell/InstanceExport.ps1 +++ b/InstanceExport/PowerShell/InstanceExport.ps1 @@ -115,8 +115,28 @@ Function CreateDirectoryIfDoesNotExist { } } +Function GetPassword() { + # assume powershell 7 first + try { + return ConvertFrom-SecureString -SecureString $password -AsPlainText + } + catch { + Log -msg $_.Exception.Message -logLevel "displayInfo" -currentDate $currentDate + } + # fallback to powershell 5 + $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password) + $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) + if ($UnsecurePassword.Length -gt 1) { + return $UnsecurePassword + } + # we're probably on some non-windows environment... fall back to unsecured + $msg = "Warning: Unable to handle password securely. Falling back to plain text password" + Log -msg $msg -logLevel "displayInfo" -currentDate $currentDate + return Read-Host "$msg. To continue, please enter the password again" +} + Function Login() { - $UnsecurePassword = ConvertFrom-SecureString -SecureString $password -AsPlainText + $UnsecurePassword = GetPassword $Body = @{ UserName = $userName