soteria-security / 365Inspect

A PowerShell script that automates the security assessment of Microsoft 365 environments.
https://soteria.io/solutions/soteria-inspect/
MIT License
563 stars 106 forks source link

When Executing from PowerShell or CMD or Windows Terminal the Script Does not Work #36

Closed asterictnl-lvdw closed 2 years ago

asterictnl-lvdw commented 2 years ago

Hello,

When the script is executed in PowerShell ISE it works normally like it should. But when I execute it at PowerShell, CMD or Windows Terminal it does not ask for authentication and goes straight to trying to run the inspectors but fails of course, because it is not authenticated.

Just reporting this. I will also look in this to see if I can find the problem.

Maybe an suggestion is to create more methods inside and then first executing the methods and do some validation on the methods and ignore execution of some methods if parameters are provided.

~Leonardo

ThoughtContagion commented 2 years ago

Can you post the command used to initiate the run of the script?

This should look like this: .\365Inspect.ps1 -OrgName $myOrg -OutPath $myPath -Auth MFA

Also, any error messages would be appreciated.

If the script is attempting to run the inspectors it believes you to already be authenticated.

asterictnl-lvdw commented 2 years ago

That is the exact script I run. Even if I put -Auth MFA it does not go to the ConnectServices Function at all. It goes straight to the Execution of Inspectors.

What the problem is, that the script lacks of Functions and does not execute some functions.

What I am testing now is some function wrapping and creating a main function that would execute all possible functions properly. This lacks of validation at the moment so I need to add that later.

ThoughtContagion commented 2 years ago

And you are running from this repository and not your fork?

ThoughtContagion commented 2 years ago

I cannot replicate the issues you are having with the code from this repository. Can you post the 365Inspect.ps1 file that you are running so that I can compare the code? The flow of code in this repository first checks for all of the necessary modules via Confirm-InstalledModules, and within that function - if all modules are present, the Connect-Services function is called, otherwise the code exits with a warning via the Confirm-Close function. Lines 58 - 178 are the relevant lines of code in this repository's 365Inspect.ps1 file.

asterictnl-lvdw commented 2 years ago

Exactly Your Script I am Running

I am running it on the CLI by either Powershell ./365Inspect.ps1 or on CMD powershell -Command ./365Inspect.ps1 with eventually the parameters and arguments.

ThoughtContagion commented 2 years ago

I've downloaded and run this multiple times, clean clones, on two separate machines - one running Windows 11 and another running Windows 10 and cannot replicate this issue. Even running from cmd.exe and calling the scripts I get the expected results. image

Can you upload the exact 365Inspect.ps1 file you are running from your machine, or provide screenshots and any error messages? Your OS version, PowerShell version info, etc... would be helpful also.

Unfortunately, we can't fix what we can't replicate.

asterictnl-lvdw commented 2 years ago

I am re-writing the parts that validate the installation and validation and sign-in processes, so-far it is going very well. I need to implement the non-mfa variant and then I can merge it with the old workflow. I will push the code to the fork so you can examine when it is done.

asterictnl-lvdw commented 2 years ago

Update: I released 365Inspect+.ps1 on my fork so you could test it out. I am adding the Changelog and updated README.md so the updates can be consulted.

ThoughtContagion commented 2 years ago

Closing this issue as the originally indicated problem cannot be replicated with the existing script in this repository.