Exports Microsoft 365 security audit results to CSV or Excel files and supports outputting specific test results as objects.
The Export-M365SecurityAuditTable function exports Microsoft 365 security audit results from an array of CISAuditResult objects or a CSV file.
It can export all results to a specified path, output a specific test result as an object, and includes options for exporting results to Excel.
Additionally, it computes hashes for the exported files and includes them in the zip archive for verification purposes.
Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [-OutputTestNumber] <String> [-WhatIf] [-Confirm] [<CommonParameters>] Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [[-ExportNestedTables]] -ExportPath <String> [-ExportOriginalTests] [-ExportToExcel] [-Prefix <String>] [-WhatIf] [-Confirm] [<CommonParameters>] Export-M365SecurityAuditTable [-CsvPath] <String> [-OutputTestNumber] <String> [-WhatIf] [-Confirm] [<CommonParameters>] Export-M365SecurityAuditTable [-CsvPath] <String> [[-ExportNestedTables]] -ExportPath <String> [-ExportOriginalTests] [-ExportToExcel] [-Prefix <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
An array of CISAuditResult objects containing the audit results. This parameter is mandatory when exporting from audit results. | true | false | |||
The path to a CSV file containing the audit results. This parameter is mandatory when exporting from a CSV file. | true | false | |||
The test number to output as an object. Valid values are "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4". This parameter is used to output a specific test result. | true | false | |||
Switch to export all test results. When specified, all test results are exported to the specified path. | false | false | False | ||
The path where the CSV or Excel files will be exported. This parameter is mandatory when exporting all tests. | true | false | |||
Switch to export the original audit results to a CSV file. When specified, the original test results are exported along with the processed results. | false | false | False | ||
Switch to export the results to an Excel file. When specified, results are exported in Excel format. | false | false | False | ||
Add Prefix to filename after date when outputting to excel or csv. Validate that the count of letters in the prefix is less than 5. |
false | false | Corp | ||
wi | false | false | |||
cf | false | false |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Export-M365SecurityAuditTable -AuditResults $object -OutputTestNumber 6.1.2 # Outputs the result of test number 6.1.2 from the provided audit results as an object.EXAMPLE 2
Export-M365SecurityAuditTable -ExportNestedTables -AuditResults $object -ExportPath "C:\temp" # Exports all audit results to the specified path in CSV format.EXAMPLE 3
Export-M365SecurityAuditTable -CsvPath "C:\temp\auditresultstoday1.csv" -OutputTestNumber 6.1.2 # Outputs the result of test number 6.1.2 from the CSV file as an object.EXAMPLE 4
Export-M365SecurityAuditTable -ExportNestedTables -CsvPath "C:\temp\auditresultstoday1.csv" -ExportPath "C:\temp" # Exports all audit results from the CSV file to the specified path in CSV format.EXAMPLE 5
Export-M365SecurityAuditTable -ExportNestedTables -AuditResults $object -ExportPath "C:\temp" -ExportOriginalTests # Exports all audit results along with the original test results to the specified path in CSV format.EXAMPLE 6
Export-M365SecurityAuditTable -ExportNestedTables -CsvPath "C:\temp\auditresultstoday1.csv" -ExportPath "C:\temp" -ExportOriginalTests # Exports all audit results from the CSV file along with the original test results to the specified path in CSV format.EXAMPLE 7
Export-M365SecurityAuditTable -ExportNestedTables -AuditResults $object -ExportPath "C:\temp" -ExportToExcel # Exports all audit results to the specified path in Excel format.
Retrieves user licenses and roles for administrative accounts from Microsoft 365 via the Graph API.
The Get-AdminRoleUserLicense function connects to Microsoft Graph and retrieves all users who are assigned administrative roles along with their user details and licenses. This function is useful for auditing and compliance checks to ensure that administrators have appropriate licenses and role assignments.
Get-AdminRoleUserLicense [-SkipGraphConnection] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
A switch parameter that, when set, skips the connection to Microsoft Graph if already established. This is useful for batch processing or when used within scripts where multiple calls are made and the connection is managed externally. | false | false | False |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Get-AdminRoleUserLicense
Get-AdminRoleUserLicense -SkipGraphConnection
Retrieves the MFA (Multi-Factor Authentication) status for Azure Active Directory users.
The Get-MFAStatus function connects to Microsoft Online Service and retrieves the MFA status for all Azure Active Directory users, excluding guest accounts. Optionally, you can specify a single user by their User Principal Name (UPN) to get their MFA status.
Get-MFAStatus [[-UserId] <String>] [-SkipMSOLConnectionChecks] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The User Principal Name (UPN) of a specific user to retrieve MFA status for. If not provided, the function retrieves MFA status for all users. | false | false | |||
false | false | False |
The output type is the type of the objects that the cmdlet emits.
Get-MFAStatus Retrieves the MFA status for all Azure Active Directory users.EXAMPLE 2
Get-MFAStatus -UserId "example@domain.com" Retrieves the MFA status for the specified user with the UPN "example@domain.com".
Grants Microsoft Graph permissions for an auditor.
This function grants the specified Microsoft Graph permissions to a user, allowing the user to perform audits. It connects to Microsoft Graph, checks if a service principal exists for the client application, creates it if it does not exist, and then grants the specified permissions. Finally, it assigns the app to the user.
Grant-M365SecurityAuditConsent [-UserPrincipalNameForConsent] <String> [-SkipGraphConnection] [-SkipModuleCheck] [-SuppressRevertOutput] [-DoNotDisconnect] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The UPN or ID of the user to grant consent for. | true | true (ByValue, ByPropertyName) | |||
If specified, skips connecting to Microsoft Graph. | false | false | False | ||
If specified, skips the check for the Microsoft.Graph module. | false | false | False | ||
If specified, suppresses the output of the revert commands. | false | false | False | ||
If specified, does not disconnect from Microsoft Graph after granting consent. | false | false | False | ||
wi | false | false | |||
cf | false | false |
The output type is the type of the objects that the cmdlet emits.
Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent user@example.com
Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent user@example.com -SkipGraphConnection
Invokes a security audit for Microsoft 365 environments.
The Invoke-M365SecurityAudit cmdlet performs a comprehensive security audit based on the specified parameters.
It allows auditing of various configurations and settings within a Microsoft 365 environment in alignment with CIS benchmarks designated "Automatic".
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELevel <String> -ProfileLevel <String> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG1 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG2 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeIG3 [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -SkipRecommendation <String[]> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The URL of the tenant admin. If not specified, none of the SharePoint Online tests will run. | false | false | |||
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 | |||
Specifies the E-Level (E3 or E5) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter. | true | false | |||
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 | |||
If specified, includes tests where IG1 is true. | true | false | False | ||
If specified, includes tests where IG2 is true. | true | false | False | ||
If specified, includes tests where IG3 is true. | true | false | False | ||
Specifies specific recommendations to include in the audit. Accepts an array of recommendation numbers. | true | false | |||
Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers. | true | false | |||
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 | @() | ||
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 | |||
If specified, the cmdlet will not establish a connection to Microsoft 365 services. | false | false | False | ||
If specified, the cmdlet will not disconnect from Microsoft 365 services after execution. | false | false | False | ||
If specified, the cmdlet will not check for the presence of required modules. | false | false | False | ||
If specified, the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them. | false | false | False | ||
Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services. | false | false | |||
wi | false | false | |||
cf | false | false |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Invoke-M365SecurityAudit # Performs a security audit using default parameters.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.EXAMPLE 3
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -IncludeIG1 # Performs a security audit while including tests where IG1 is true.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.EXAMPLE 5
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" PS> Export-M365SecurityAuditTable -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests -ExportAllTestsEXAMPLE 6
# (PowerShell 7.x Only) Creating a new authentication object for the security audit for app-based authentication. PS> $authParams = New-M365SecurityAuditAuthObject ` -ClientCertThumbPrint "ABCDEF1234567890ABCDEF1234567890ABCDEF12" ` -ClientId "12345678-1234-1234-1234-123456789012" ` -TenantId "12345678-1234-1234-1234-123456789012" ` -OnMicrosoftUrl "yourcompany.onmicrosoft.com" ` -SpAdminUrl "https://yourcompany-admin.sharepoint.com" Invoke-M365SecurityAudit -AuthParams $authParams -TenantAdminUrl "https://yourcompany-admin.sharepoint.com" # Or: PS> $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation # Captures the audit results into a variable and exports them to a CSV file (Nested tables will be truncated). Output: CISAuditResult[] auditResults.csvEXAMPLE 7
Invoke-M365SecurityAudit -WhatIf 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".
Creates a new CISAuthenticationParameters object for Microsoft 365 authentication.
The New-M365SecurityAuditAuthObject function constructs a new CISAuthenticationParameters object
containing the necessary credentials and URLs for authenticating to various Microsoft 365 services.
It validates input parameters to ensure they conform to expected formats and length requirements.
An app registration in Azure AD with the required permissions to EXO, SPO, MSTeams and MgGraph is needed.
New-M365SecurityAuditAuthObject [-ClientCertThumbPrint] <String> [-ClientId] <String> [-TenantId] <String> [-OnMicrosoftUrl] <String> [-SpAdminUrl] <String> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The thumbprint of the client certificate used for authentication. It must be a 40-character hexadecimal string. This certificate is used to authenticate the application in Azure AD. |
true | false | |||
The Client ID (Application ID) of the Azure AD application. It must be a valid GUID format. | true | false | |||
The Tenant ID of the Azure AD directory. It must be a valid GUID format representing your Microsoft 365 tenant. | true | false | |||
The URL of your onmicrosoft.com domain. It should be in the format 'example.onmicrosoft.com'. | true | false | |||
The SharePoint admin URL, which should end with '-admin.sharepoint.com'. This URL is used for connecting to SharePoint Online. | true | false |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
$authParams = New-M365SecurityAuditAuthObject -ClientCertThumbPrint "ABCDEF1234567890ABCDEF1234567890ABCDEF12" ` -ClientId "12345678-1234-1234-1234-123456789012" ` -TenantId "12345678-1234-1234-1234-123456789012" ` -OnMicrosoftUrl "yourcompany.onmicrosoft.com" ` -SpAdminUrl "https://yourcompany-admin.sharepoint.com" Creates a new CISAuthenticationParameters object with the specified credentials and URLs, validating each parameter's format and length.
Removes rows from an Excel worksheet where the 'CSV_Status' column is empty and saves the result to a new file.
The Remove-RowsWithEmptyCSVStatus function imports data from a specified worksheet in an Excel file, checks for the presence of the 'CSV_Status' column, and filters out rows where the 'CSV_Status' column is empty. The filtered data is then exported to a new Excel file with a '-Filtered' suffix added to the original file name.
Remove-RowsWithEmptyCSVStatus [-FilePath] <String> [-WorksheetName] <String> [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The path to the Excel file to be processed. | true | false | |||
The name of the worksheet within the Excel file to be processed. | true | false |
Remove-RowsWithEmptyCSVStatus -FilePath "C:\Reports\Report.xlsx" -WorksheetName "Sheet1" This command imports data from the "Sheet1" worksheet in the "Report.xlsx" file, removes rows where the 'CSV_Status' column is empty, and saves the filtered data to a new file named "Report-Filtered.xlsx" in the same directory.
Synchronizes and updates data in an Excel worksheet with new information from a CSV file, including audit dates.
The Sync-CISExcelAndCsvData function merges and updates data in a specified Excel worksheet from a CSV file. This includes adding or updating fields for connection status, details, failure reasons, and the date of the update. It's designed to ensure that the Excel document maintains a running log of changes over time, ideal for tracking remediation status and audit history.
Sync-CISExcelAndCsvData [[-ExcelPath] <String>] [[-CsvPath] <String>] [[-SheetName] <String>] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Specifies the path to the Excel file to be updated. This parameter is mandatory. | false | false | |||
Specifies the path to the CSV file containing new data. This parameter is mandatory. | false | false | |||
Specifies the name of the worksheet in the Excel file where data will be merged and updated. This parameter is mandatory. | false | false |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -CsvPath "path\to\data.csv" -SheetName "AuditData" Updates the 'AuditData' worksheet in 'excel.xlsx' with data from 'data.csv', adding new information and the date of the update.