From 6e4cc874b06baa9c88a5f30d1511cdee4ddcd431 Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Fri, 7 Nov 2025 20:42:58 +0100 Subject: [PATCH] PS 7 bug fixes --- Elysium.ps1 | 27 +++++++++++++++++++++++++-- Extract-NTHashes.ps1 | 6 ------ Test-WeakADPasswords.ps1 | 6 ------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Elysium.ps1 b/Elysium.ps1 index 1a23e37..fa7b2f0 100644 --- a/Elysium.ps1 +++ b/Elysium.ps1 @@ -100,11 +100,21 @@ do { } '2' { Write-Host "Testing Weak AD Passwords..." - & (Join-Path -Path $PSScriptRoot -ChildPath 'Test-WeakADPasswords.ps1') + $testScript = Join-Path -Path $PSScriptRoot -ChildPath 'Test-WeakADPasswords.ps1' + if ($PSVersionTable.PSEdition -eq 'Desktop') { + & $testScript + } else { + Invoke-WindowsPowerShellScript -ScriptPath $testScript + } } '3' { Write-Host "Extracting and Sending Current Hashes..." - & (Join-Path -Path $PSScriptRoot -ChildPath 'Extract-NTHashes.ps1') + $extractScript = Join-Path -Path $PSScriptRoot -ChildPath 'Extract-NTHashes.ps1' + if ($PSVersionTable.PSEdition -eq 'Desktop') { + & $extractScript + } else { + Invoke-WindowsPowerShellScript -ScriptPath $extractScript + } } '4' { Write-Host "Uninstalling..." @@ -128,3 +138,16 @@ do { } finally { Stop-OrchestratorTranscript } +function Invoke-WindowsPowerShellScript { + param([string]$ScriptPath) + $powershellCmd = Get-Command -Name 'powershell.exe' -ErrorAction SilentlyContinue + if (-not $powershellCmd) { + throw "Windows PowerShell (powershell.exe) was not found. Install it or run the script from a Desktop edition session." + } + $args = @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $ScriptPath) + & $powershellCmd.Path @args + $exitCode = $LASTEXITCODE + if ($exitCode -ne 0) { + throw ("Windows PowerShell script '{0}' exited with code {1}." -f $ScriptPath, $exitCode) + } +} diff --git a/Extract-NTHashes.ps1 b/Extract-NTHashes.ps1 index edf67a8..7f8e4e2 100644 --- a/Extract-NTHashes.ps1 +++ b/Extract-NTHashes.ps1 @@ -22,12 +22,6 @@ This script will connect to selected domain (defined in ElysiumSettings.txt) usi $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest -[string]$commonHelper = Join-Path -Path $PSScriptRoot -ChildPath 'Elysium.Common.ps1' -if (-not (Test-Path -LiteralPath $commonHelper)) { throw "Common helper not found at $commonHelper" } -. $commonHelper -if ($PSVersionTable.PSEdition -ne 'Desktop') { - Restart-WithWindowsPowerShellIfAvailable -BoundParameters $PSBoundParameters -UnboundArguments $MyInvocation.UnboundArguments -} $scriptRoot = $PSScriptRoot diff --git a/Test-WeakADPasswords.ps1 b/Test-WeakADPasswords.ps1 index 0ed0d3e..efe4149 100644 --- a/Test-WeakADPasswords.ps1 +++ b/Test-WeakADPasswords.ps1 @@ -24,12 +24,6 @@ This script will test the passwords of selected domain (defined in ElysiumSettin # Enable verbose output $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest -[string]$commonHelper = Join-Path -Path $PSScriptRoot -ChildPath 'Elysium.Common.ps1' -if (-not (Test-Path -LiteralPath $commonHelper)) { throw "Common helper not found at $commonHelper" } -. $commonHelper -if ($PSVersionTable.PSEdition -ne 'Desktop') { - Restart-WithWindowsPowerShellIfAvailable -BoundParameters $PSBoundParameters -UnboundArguments $MyInvocation.UnboundArguments -} $VerbosePreference = "SilentlyContinue"