From db04af63d5d3d42ea31a368487f5adb79673e813 Mon Sep 17 00:00:00 2001 From: silverhack Date: Mon, 10 Jun 2024 18:56:09 +0200 Subject: [PATCH] update config and core modules --- config/monkey365.config | 4 +-- .../monkeyjob/Localized/en-US/monkeyjob.psd1 | 1 + .../monkeyjob/Localized/monkeyjob.psd1 | 1 + .../monkeyjob/public/Remove-MonkeyJob.ps1 | 31 ++++++++++++++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/config/monkey365.config b/config/monkey365.config index e8ad6232..e556f038 100644 --- a/config/monkey365.config +++ b/config/monkey365.config @@ -25,8 +25,8 @@ }, "ruleSettings": { "rules": "rules/", - "azureDefaultRuleset": "rules/rulesets/cis_azure_1.5.json", - "m365DefaultRuleset": "rules/rulesets/cis_m365_1.5.json" + "azureDefaultRuleset": "rules/rulesets/cis_azure_2.0.json", + "m365DefaultRuleset": "rules/rulesets/cis_m365_2.0.json" }, "logging": { "default":[ diff --git a/core/modules/monkeyjob/Localized/en-US/monkeyjob.psd1 b/core/modules/monkeyjob/Localized/en-US/monkeyjob.psd1 index aa9f56fd..47e6f5ec 100644 --- a/core/modules/monkeyjob/Localized/en-US/monkeyjob.psd1 +++ b/core/modules/monkeyjob/Localized/en-US/monkeyjob.psd1 @@ -22,4 +22,5 @@ RemoveDummyFunctionMessage = Removing dummy function {0} ScriptBlockError = Unable to create ScriptBlock object CommandNotRecognized = Command {0} cannot be imported + UnableToRemoveJob = "Unable to remove job {0}" '@ \ No newline at end of file diff --git a/core/modules/monkeyjob/Localized/monkeyjob.psd1 b/core/modules/monkeyjob/Localized/monkeyjob.psd1 index aa9f56fd..47e6f5ec 100644 --- a/core/modules/monkeyjob/Localized/monkeyjob.psd1 +++ b/core/modules/monkeyjob/Localized/monkeyjob.psd1 @@ -22,4 +22,5 @@ RemoveDummyFunctionMessage = Removing dummy function {0} ScriptBlockError = Unable to create ScriptBlock object CommandNotRecognized = Command {0} cannot be imported + UnableToRemoveJob = "Unable to remove job {0}" '@ \ No newline at end of file diff --git a/core/modules/monkeyjob/public/Remove-MonkeyJob.ps1 b/core/modules/monkeyjob/public/Remove-MonkeyJob.ps1 index 97b0149e..8da6a859 100644 --- a/core/modules/monkeyjob/public/Remove-MonkeyJob.ps1 +++ b/core/modules/monkeyjob/public/Remove-MonkeyJob.ps1 @@ -106,8 +106,28 @@ Function Remove-MonkeyJob{ } } } - if($PSBoundParameters.ContainsKey('Force')){ - [void]$MonkeyJob.Job.InnerJob.Stop() + If ($MonkeyJob.Job.State -notmatch 'Completed|Failed|Stopped') { + if($PSBoundParameters.ContainsKey('Force')){ + [void]$MonkeyJob.Job.InnerJob.Stop(); + $MonkeyJob.Job.InnerJob.Dispose(); + if(!$PSBoundParameters.ContainsKey('KeepRunspacePool')){ + #$MonkeyJob.Job.InnerJob.RunspacePool.Close(); + $MonkeyJob.Job.InnerJob.RunspacePool.Dispose(); + } + if($MonkeyJob.Job.State -ne [System.Management.Automation.JobState]::Stopped){ + $MonkeyJob.Job.StopJob(); + } + $MonkeyJob.Job.Dispose(); + #Dispose task + if($null -ne $MonkeyJob.Task -and $MonkeyJob.Task.Status -match 'Canceled|Faulted|RanToCompletion'){ + $MonkeyJob.Task.Dispose(); + $MonkeyJob.Task = $null; + } + [void]$MonkeyJobs.Remove($MonkeyJob) + } + Else{ + Write-Warning ($script:messages.UnableToRemoveJob -f $MonkeyJob.Id) + } } #Clean MonkeyJob object #$MonkeyJob.Job.InnerJob.Stop(); @@ -120,11 +140,14 @@ Function Remove-MonkeyJob{ $MonkeyJob.Job.StopJob(); } $MonkeyJob.Job.Dispose(); - if($null -ne $MonkeyJob.Task){ + if($null -ne $MonkeyJob.Task -and $MonkeyJob.Task.Status -match 'Canceled|Faulted|RanToCompletion'){ $MonkeyJob.Task.Dispose(); $MonkeyJob.Task = $null; + [void]$MonkeyJobs.Remove($MonkeyJob) + } + Else{ + Write-Warning ($script:messages.UnableToRemoveJob -f $MonkeyJob.Id) } - [void]$MonkeyJobs.Remove($MonkeyJob) #Perform garbage collection [gc]::Collect() }