Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Invoke-SCuBACached if no provider json #1329

Closed
adhilto opened this issue Sep 24, 2024 · 0 comments · Fixed by #1334 or #1342
Closed

Bug with Invoke-SCuBACached if no provider json #1329

adhilto opened this issue Sep 24, 2024 · 0 comments · Fixed by #1334 or #1342
Assignees
Labels
bug This issue or pull request addresses broken functionality
Milestone

Comments

@adhilto
Copy link
Collaborator

adhilto commented Sep 24, 2024

🐛 Summary

When merging the json was made default, the Invoke-ScubaCached function was modified to be compatible with the ScubaResults.json file. However, this introduced a bug. What it tries to do is if there is no provider output json file, open the ScubaResults.json file and save one from the data in the Raw field. It tries to save it with this call:

Set-Utf8NoBom -Content $ProviderContent `
                -Location $ProviderJSONFilePath -FileName "$OutProviderFileName.json"

Problem is, $ProviderJSONFilePath already has the "$OutProviderFileName.json" part embedded in it.

$ProviderJSONFilePath = Join-Path -Path $OutPath -ChildPath "$($OutProviderFileName).json"

So, essentially, we're trying to save the file as "example-out-path/ProviderSettingsExport.json/ProviderSettingsExport.json". However, this call fails because the Set-Utf8NoBom function requires the -Location path to already exist, which in this case, it doesn't.

The fix is easy, we just need to replace that Set-Utf8NoBom call with this:

$ActualSavedLocation = Set-Utf8NoBom -Content $ProviderContent `
    -Location $OutPath -FileName "$OutProviderFileName.json"

To reproduce

  1. Create output with merged json. From the latest on main, this is as easy as Invoke-Scuba
  2. Invoke-ScubaCached -OutPath .\path-to-output-folder-from-step-1\ -ExportProvider $false

Expected behavior

Invoke-ScubaCached to run successfully.

Any helpful log output or screenshots

Resolve-Path : Cannot find path
C:\Users\adhilto\Repos\ScubaGear\M365BaselineConformance_2024_09_16_19_42_27\ProviderSettingsExport.json' because it does not exist.
At C:\Users\adhilto\Repos\ScubaGear\PowerShell\ScubaGear\Modules\Utility\Utility.psm1:36 char:
+         $ResolvedPath = $(Resolve-Path $Location).
+                           ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:\Users\adhilt...ingsExport.json:String) [Resolve-Path], 
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand 
@adhilto adhilto added the bug This issue or pull request addresses broken functionality label Sep 24, 2024
@buidav buidav self-assigned this Sep 24, 2024
@buidav buidav added this to the Jellyfish milestone Sep 24, 2024
@buidav buidav linked a pull request Sep 24, 2024 that will close this issue
16 tasks
@adhilto adhilto mentioned this issue Sep 27, 2024
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue or pull request addresses broken functionality
Projects
None yet
2 participants