Register for and download CIS Benchmarks
Export-M365SecurityAuditTableInvoke-M365SecurityAudit
EXAMPLES
# Example 1: Performing a security audit based on CIS benchmarks $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ApprovedCloudStorageProviders "DropBox" -ApprovedFederatedDomains "northwind.com" # Example 2: Exporting a security audit and it's nested tables to zipped CSV files Export-M365SecurityAuditTable -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests -ExportAllTests # Output Ex: 2024.07.07_14.55.55_M365FoundationsAudit_368B2E2F.zip # Example 3: Retrieving licenses for users in administrative roles Get-AdminRoleUserLicense # Example 4: Getting MFA status of users Get-MFAStatus -UserId "user@domain.com" # Example 5: Removing rows with empty status values from a CSV file Remove-RowsWithEmptyCSVStatus -FilePath "C:\Reports\Report.xlsx" -WorksheetName "Sheet1" # Example 6: Synchronizing CIS benchmark data with audit results Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -CsvPath "path\to\data.csv" -SheetName "Combined Profiles" # Example 7: Granting Microsoft Graph permissions to the auditor Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent 'user@example.com'
NOTE
Ensure that you have the necessary permissions and administrative roles in your Microsoft 365 environment to run these cmdlets. Proper configuration and setup are required for accurate audit results.
TROUBLESHOOTING NOTE
If you encounter any issues while using the cmdlets, ensure that your environment meets the module prerequisites. Check for any updates or patches that may address known bugs. For issues related to specific cmdlets, refer to the individual help files for troubleshooting tips.
SEE ALSO
Export-M365SecurityAuditTable
Synopsis
Exports Microsoft 365 security audit results to CSV or Excel files and supports outputting specific test results as objects.
Examples
EXAMPLE 1
Note
Creation Date: 2024-04-15 Purpose/Change: Initial function development to support Microsoft 365 administrative role auditing.
Examples
EXAMPLE 1
Note
The function requires the MSOL module to be installed and connected to your tenant. Ensure that you have the necessary permissions to read user and MFA status information.
Examples
EXAMPLE 1
Note
This function requires the Microsoft.Graph module version 2.4.0 or higher.
Examples
EXAMPLE 1
Invoke-M365SecurityAudit
Synopsis
Invokes a security audit for Microsoft 365 environments.
Syntax
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm][<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELevel <String> -ProfileLevel <String> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck][-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELevel <String> -ProfileLevel <String> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG1 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections][-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG1 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG2 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections][-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG2 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG3 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections][-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG3 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck][-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -SkipRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>]Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -SkipRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck][-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>]
Parameters
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
TenantAdminUrl | The URL of the tenant admin. If not specified, none of the SharePoint Online tests will run. | false | false | ||
DomainName | The domain name of the Microsoft 365 environment to test. This parameter is not mandatory and by default it will pass/fail all found domains as a group if a specific domain is not specified. | false | false | ||
ELevel | Specifies the E-Level (E3 or E5) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter. | true | false | ||
ProfileLevel | Specifies the profile level (L1 or L2) for the audit. This parameter is optional and can be combined with the ELevel parameter. | true | false | ||
IncludeIG1 | If specified, includes tests where IG1 is true. | true | false | False | |
IncludeIG2 | If specified, includes tests where IG2 is true. | true | false | False | |
IncludeIG3 | If specified, includes tests where IG3 is true. | true | false | False | |
IncludeRecommendation | Specifies specific recommendations to include in the audit. Accepts an array of recommendation numbers. | true | false | ||
SkipRecommendation | Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers. | true | false | ||
ApprovedCloudStorageProviders | Specifies the approved cloud storage providers for the audit. Accepts an array of cloud storage provider names. | false | false | @() | |
ApprovedFederatedDomains | Specifies the approved federated domains for the audit test 8.2.1. Accepts an array of allowed domain names. | false | false | ||
DoNotConnect | If specified, the cmdlet will not establish a connection to Microsoft 365 services. | false | false | False | |
DoNotDisconnect | If specified, the cmdlet will not disconnect from Microsoft 365 services after execution. | false | false | False | |
NoModuleCheck | If specified, the cmdlet will not check for the presence of required modules. | false | false | False | |
DoNotConfirmConnections | If specified, the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them. | false | false | False | |
WhatIf | wi | false | false | ||
Confirm | cf | false | false |
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
TenantAdminUrl | The URL of the tenant admin. If not specified, none of the SharePoint Online tests will run. | false | false | ||
DomainName | The domain name of the Microsoft 365 environment to test. It is optional and will trigger various tests to run only for the specified domain. Tests Affected: 2.1.9/Test-EnableDKIM, 1.3.1/Test-PasswordNeverExpirePolicy, 2.1.4/Test-SafeAttachmentsPolicy | false | false | ||
ELevel | Specifies the E-Level (E3 or E5) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter. | true | false | ||
ProfileLevel | Specifies the profile level (L1 or L2) for the audit. This parameter is mandatory, but only when ELevel is selected. Otherwise it is not required. | true | false | ||
IncludeIG1 | If specified, includes tests where IG1 is true. | true | false | False | |
IncludeIG2 | If specified, includes tests where IG2 is true. | true | false | False | |
IncludeIG3 | If specified, includes tests where IG3 is true. | true | false | False | |
IncludeRecommendation | Specifies specific recommendations to include in the audit. Accepts an array of recommendation numbers. | true | false | ||
SkipRecommendation | Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers. | true | false | ||
ApprovedCloudStorageProviders | Specifies the approved cloud storage providers for the audit. Accepts an array of cloud storage provider names for test 8.1.1/Test-TeamsExternalFileSharing. Acceptable values: 'GoogleDrive', 'ShareFile', 'Box', 'DropBox', 'Egnyte' | false | false | @() | |
ApprovedFederatedDomains | Specifies the approved federated domains for the audit test 8.2.1/Test-TeamsExternalAccess. Accepts an array of allowed domain names. Additional Tests may include this parameter in the future. | false | false | ||
DoNotConnect | If specified, the cmdlet will not establish a connection to Microsoft 365 services. | false | false | False | |
DoNotDisconnect | If specified, the cmdlet will not disconnect from Microsoft 365 services after execution. | false | false | False | |
NoModuleCheck | If specified, the cmdlet will not check for the presence of required modules. | false | false | False | |
DoNotConfirmConnections | If specified, the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them. | false | false | False | |
WhatIf | wi | false | false | ||
Confirm | cf | false | false |
Inputs
- None. You cannot pipe objects to Invoke-M365SecurityAudit.
Note
- This module is based on CIS benchmarks. - Governed by the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. - Commercial use is not permitted. This module cannot be sold or used for commercial purposes. - Modifications and sharing are allowed under the same license. - For full license details, visit: https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en - Register for CIS Benchmarks at: https://www.cisecurity.org/cis-benchmarks
Examples
EXAMPLE 1
Invoke-M365SecurityAudit
Performs a security audit using default parameters.
Output:
Performs a security audit using default parameters. Output:
Status : Fail
ELevel : E3
ProfileLevel: L1
Connection : Microsoft Graph
Rec : 1.1.1
Result : False
Details : Non-compliant accounts:
Username | Roles | HybridStatus | Missing Licence
user1@domain.com| Global Administrator | Cloud-Only | AAD_PREMIUM
user2@domain.com| Global Administrator | Hybrid | AAD_PREMIUM, AAD_PREMIUM_P2
FailureReason: Non-Compliant Accounts: 2
EXAMPLE 2
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ELevel "E5" -ProfileLevel "L1"
Performs a security audit for the E5 level and L1 profile in the specified Microsoft 365 environment.
Output:
Performs a security audit for the E5 level and L1 profile in the specified Microsoft 365 environment. Output:
Status : Fail
ELevel : E5
ProfileLevel: L1
Connection : Microsoft Graph
Rec : 1.1.1
Result : False
Details : Non-compliant accounts:
Username | Roles | HybridStatus | Missing Licence
user1@domain.com| Global Administrator | Cloud-Only | AAD_PREMIUM
user2@domain.com| Global Administrator | Hybrid | AAD_PREMIUM, AAD_PREMIUM_P2
FailureReason: Non-Compliant Accounts: 2
EXAMPLE 3
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -IncludeIG1
Performs an audit including all tests where IG1 is true.
Output:
Performs an audit including all tests where IG1 is true. Output:
Status : Fail
ELevel : E3
ProfileLevel: L1
Connection : Microsoft Graph
Rec : 1.1.1
Result : False
Details : Non-compliant accounts:
Username | Roles | HybridStatus | Missing Licence
user1@domain.com| Global Administrator | Cloud-Only | AAD_PREMIUM
user2@domain.com| Global Administrator | Hybrid | AAD_PREMIUM, AAD_PREMIUM_P2
FailureReason: Non-Compliant Accounts: 2
EXAMPLE 4
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -SkipRecommendation '1.1.3', '2.1.1'
Performs an audit while excluding specific recommendations 1.1.3 and 2.1.1.
Output:
Performs an audit while excluding specific recommendations 1.1.3 and 2.1.1. Output:
Status : Fail
ELevel : E3
ProfileLevel: L1
Connection : Microsoft Graph
Rec : 1.1.1
Result : False
Details : Non-compliant accounts:
Username | Roles | HybridStatus | Missing Licence
user1@domain.com| Global Administrator | Cloud-Only | AAD_PREMIUM
user2@domain.com| Global Administrator | Hybrid | AAD_PREMIUM, AAD_PREMIUM_P2
FailureReason: Non-Compliant Accounts: 2
EXAMPLE 5
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com"
PS> Export-M365SecurityAuditTable -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests -ExportAllTests
Or:
PS> $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation
Captures the audit results into a variable and exports them to a CSV filefile (Nested tables will be truncated).
Output:
CISAuditResult[]
auditResults.csv
EXAMPLE 6
Invoke-M365SecurityAudit -WhatIf
Displays what would happen if the cmdlet is run without actually performing the audit.
Output:
Displays what would happen if the cmdlet is run without actually performing the audit. Output:
What if: Performing the operation "Invoke-M365SecurityAudit" on target "Microsoft 365 environment".
Links
Note
This function requires the ImportExcel module to be installed.
Examples
EXAMPLE 1
Note
- Ensure that the 'ImportExcel' module is installed and up to date to handle Excel file manipulations. - It is recommended to back up the Excel file before running this function to avoid accidental data loss. - The CSV file should have columns that match expected headers like 'Connection', 'Details', 'FailureReason', and 'Status' for correct data mapping.
Examples
EXAMPLE 1