From 1974fee772280ae900d4c055a4e15635a9fe9433 Mon Sep 17 00:00:00 2001 From: Nathan Gerhart Date: Mon, 3 Mar 2025 16:53:04 -0700 Subject: [PATCH 1/3] InstanceExport: improve login process Our powershell 5 version doesn't work on non-windows computers, and the powershell 7 version doesn't work on powershell 5... This seems like a reasonable balance for something we've had several help tickets on --- InstanceExport/PowerShell/InstanceExport.ps1 | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 From b8f7d02e74c3b9b9fd18a291af7908e0da07358e Mon Sep 17 00:00:00 2001 From: Nathan Gerhart Date: Mon, 3 Mar 2025 17:03:24 -0700 Subject: [PATCH 2/3] GitHub Actions: publish releases when tagged This gives users the option to download the signed version (vs run unsigned) --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc0c9e5..0b998ce 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 with: name: ${{ env.ARTIFACT_NAME }} - path: ./InstanceExport/PowerShell/InstanceExport.ps1 \ No newline at end of file + path: ./InstanceExport/PowerShell/InstanceExport.ps1 From dfdee35f0a4c65afb5048278e13ca293b11ec229 Mon Sep 17 00:00:00 2001 From: Nathan Gerhart Date: Mon, 3 Mar 2025 17:11:06 -0700 Subject: [PATCH 3/3] GitHub Actions: use latest version of upload-artifact v3 was deprecated in January --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0b998ce..3e51586 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,7 @@ jobs: 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