Skip to content

Conversation

@JrOrOneEquals1
Copy link

Allows users to skip passing a technique number if TestGuids is provided.
Parses $TestGuids and gets the associated technique number, then calls the main command with the necessary arguments for each guid passed.

Example run:
Invoke-AtomicTest -TestGuids 970ab6a1-0157-4f3f-9a73-ec4166754b23,53cf1903-0fa7-4177-ab14-f358ae809eec -ShowDetails

Which would then call:
Invoke-AtomicTest T1016 -TestGuids 970ab6a1-0157-4f3f-9a73-ec4166754b23 -ShowDetails
Invoke-AtomicTest T1016.002 -TestGuids 53cf1903-0fa7-4177-ab14-f358ae809eec -ShowDetails

Allows users to skip passing a technique number if TestGuids is provided. Works by parsing the atomics for each guid passed, then calling the original function with the associated technique number and guid along with any other arguments passed.
@cyberbuff cyberbuff linked an issue Mar 15, 2025 that may be closed by this pull request
Copy link
Collaborator

@cyberbuff cyberbuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @JrOrOneEquals1 This is a great addition. Thanks for your contribution. I will review this PR over the weekend and test it on all the 3 platforms. Requested a minor change.

Comment on lines 205 to 269
if ($ShowDetails) {
$Parameters["ShowDetails"] = $ShowDetails
}

if ($ShowDetailsBrief) {
$Parameters["ShowDetailsBrief"] = $ShowDetailsBrief
}

if ($null -ne $TestNumbers) {
$Parameters["TestNumbers"] = $TestNumbers
}

if ($null -ne $TestNames) {
$Parameters["TestNames"] = $TestNames
}

if ($CheckPrereqs) {
$Parameters["CheckPrereqs"] = $CheckPrereqs
}

if ($PromptForInputArgs) {
$Parameters["PromptForInputArgs"] = $PromptForInputArgs
}

if ($GetPrereqs) {
$Parameters["GetPrereqs"] = $GetPrereqs
}

if ($Cleanup) {
$Parameters["Cleanup"] = $Cleanup
}

if ($NoExecutionLog) {
$Parameters["NoExecutionLog"] = $NoExecutionLog
}

if ($Force) {
$Parameters["Force"] = $Force
}

if ($null -ne $InputArgs) {
$Parameters["InputArgs"] = $InputArgs
}

if ($PSBoundParameters.ContainsKey('Session')) {
if ( $null -eq $Session ) {
Write-Error "The provided session is null and cannot be used."
continue
}
else {
$Parameters["Session"] = $Session
}
}

if ($Interactive) {
$Parameters["Interactive"] = $Interactive
}

if ($KeepStdOutStdErrFiles) {
$Parameters["KeepStdOutStdErrFiles"] = $KeepStdOutStdErrFiles
}

if ($LoggingModule) {
$Parameters["LoggingModule"] = $LoggingModule
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor correction. This portion can be shortened to

# Copy all bound parameters except TestGuids (which is handled separately)
$PSBoundParameters.GetEnumerator() | Where-Object { $_.Key -ne 'TestGuids' } | ForEach-Object {
    $Parameters[$_.Key] = $_.Value
}

# Special handling for Session parameter
if ($Parameters.ContainsKey('Session') -and $null -eq $Parameters['Session']) {
    Write-Error "The provided session is null and cannot be used."
    continue
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed that, thank you for the suggestion!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberbuff sorry for getting back again so late! I was looking at the failed check for this and from what I can tell, it seems like it is calling the code with a null Session parameter, which then causes the script to fall into the statement where it writes the error, which is supposed to happen under those conditions. The test just sees that it had an exit code 1 and (seemingly incorrectly) says it failed. Am I understanding that right, or is there a problem with the script getting to that point when it shouldn't that should be resolved?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberbuff can you help with this one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey guys. Apologies for the delay. Its a linting error. I dont have access to make changes in your branch. You need to install PSScriptAnalyzer and run

Install-Module -Name PSScriptAnalyzer -Force
Invoke-ScriptAnalyzer -Recurse ./ -Settings ./PSScriptAnalyzerSettings.psd1 -Fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea: Allow Atomics to be run Solely by test GUID

3 participants