48 Commits

Author SHA1 Message Date
Doug Rios
4b3a0b7505 Merge pull request #148 from CriticalSolutionsNetwork/Testing-Automations
Testing automations
2024-08-04 15:46:49 -05:00
DrIOS
042bf7b37c docs: update help docs 2024-08-04 15:44:12 -05:00
DrIOS
69ae64562f docs: update help docs 2024-08-04 15:40:50 -05:00
DrIOS
c64325e773 docs: update help docs 2024-08-04 15:34:28 -05:00
DrIOS
c341db53c5 docs: update help docs 2024-08-04 15:17:21 -05:00
DrIOS
2f5c653cc8 docs: Update CHANGELOG 2024-08-04 14:53:21 -05:00
DrIOS
00600123f3 docs: Update readme and html help 2024-08-04 14:50:58 -05:00
DrIOS
0cb1643341 docs: Update readme and html help 2024-08-04 14:47:45 -05:00
DrIOS
939980b087 docs: Update readme and html help 2024-08-04 14:29:42 -05:00
DrIOS
f375fdd5ef rename function 2024-08-04 14:13:35 -05:00
DrIOS
0ea930c708 rename function 2024-08-04 14:13:25 -05:00
Doug Rios
f9e3b5faed Merge pull request #149 from CriticalSolutionsNetwork/main
Update README.md
2024-08-04 13:56:38 -05:00
Doug Rios
4613d592d1 Update README.md 2024-08-04 13:54:55 -05:00
DrIOS
da968db3e2 change: refactor Get-CISSpoOutput to support application auth using Pnp Powershell 2024-08-04 13:51:29 -05:00
DrIOS
357f284d08 add: test number to error 2024-08-04 13:49:58 -05:00
DrIOS
9e3058add4 add: test number to Get-TestError output 2024-08-04 13:49:13 -05:00
DrIOS
d7d16ff0b5 add: App Authentication test 2024-08-03 18:52:46 -05:00
DrIOS
45eb961554 Fix: Vaugue parameter name 2024-08-03 11:43:42 -05:00
DrIOS
686e805f6a Fix: Vaugue parameter name 2024-08-03 11:42:59 -05:00
DrIOS
63edc13261 fix: Export original and all tests 2024-08-03 11:29:15 -05:00
DrIOS
9508130ddd fix: compatibility version 2024-08-03 11:28:46 -05:00
DrIOS
db73d755ed fix: Output suppression 2024-08-01 21:14:56 -05:00
Doug Rios
37e2b70ba4 Merge pull request #146 from CriticalSolutionsNetwork/Fix-pw-notification-test
Fix pw notification test
2024-07-23 08:17:32 -05:00
DrIOS
8acae46b98 docs: Update CHANGELOG 2024-07-23 07:53:00 -05:00
DrIOS
1fd460c84d fix: notification window for 1.3.1 2024-07-23 07:51:15 -05:00
Doug Rios
9f28c976ce Merge pull request #144 from CriticalSolutionsNetwork/Test-Help
docs: Update Help Wiki
2024-07-07 17:45:21 -05:00
DrIOS
1ec287031c docs: Update Help Wiki 2024-07-07 17:43:25 -05:00
DrIOS
de89312352 docs: Update Help Wiki 2024-07-07 17:41:04 -05:00
Doug Rios
1717b60891 Merge pull request #142 from CriticalSolutionsNetwork/Revert-and-refactor-1.3.3,6.1.2,6.1.3
Revert and refactor 1.3.3,2.1.4,6.1.2,6.1.3
2024-07-07 17:24:24 -05:00
DrIOS
6624bde267 docs: Update CHANGELOG 2024-07-07 17:21:40 -05:00
DrIOS
e4277afdb7 docs: Update Help README/HTML 2024-07-07 17:15:26 -05:00
DrIOS
7688071899 docs: Update Markdown 2024-07-07 17:15:05 -05:00
DrIOS
e1ab050e69 docs: Update Comment Help 2024-07-07 17:00:42 -05:00
DrIOS
7226afd198 docs: Update Comment Help 2024-07-07 16:42:55 -05:00
DrIOS
337a21bc7d docs: Update Comment Help 2024-07-07 16:37:38 -05:00
DrIOS
14ed9f6598 docs: Update Comment Help 2024-07-07 16:32:50 -05:00
DrIOS
5ddcd4466e docs: Update CHANGELOG 2024-07-07 16:21:05 -05:00
DrIOS
228c58cef3 fix: Safe Attachments logic 2024-07-07 16:18:43 -05:00
DrIOS
fe04175798 fix: formatting of 1.3.3 here string 2024-07-07 13:06:19 -05:00
DrIOS
8197187f70 docs: Update CHANGELOG 2024-07-07 13:02:11 -05:00
DrIOS
f830bdf2f0 docs: Update testfile 2024-07-07 12:56:02 -05:00
DrIOS
e86c61d221 change: Get-Action Testing-Refactor export 2024-07-07 12:48:39 -05:00
DrIOS
17647d7180 change: Get-Action Testing-DONE 2024-07-07 12:18:38 -05:00
DrIOS
d941459ac0 change: Get-Action Testing 2024-07-07 12:11:06 -05:00
DrIOS
4557c1806f change: Get-Action Testing 2024-07-07 12:01:34 -05:00
DrIOS
fcaebf1db1 change: Get-Action Testing 2024-07-07 11:58:16 -05:00
DrIOS
ff1162f962 change: Test-ExternalSharingCalendars reverted to simple test 2024-07-07 10:25:15 -05:00
DrIOS
f91af6e725 change: Test-ExternalSharingCalendars reverted to simple test 2024-07-07 10:24:32 -05:00
54 changed files with 2903 additions and 1665 deletions

1
.gitignore vendored
View File

@@ -17,3 +17,4 @@ node_modules
package-lock.json package-lock.json
Aligned.xlsx Aligned.xlsx
test-gh1.ps1 test-gh1.ps1
ModdedModules/*

View File

@@ -4,6 +4,45 @@ The format is based on and uses the types of changes according to [Keep a Change
## [Unreleased] ## [Unreleased]
### Added
- Added `New-M365SecurityAuditAuthObject` function to create a new authentication object for the security audit for app-based authentication.
### Changed
- Changed authentication options to include parameter for authenticating with a certificate.
- Changed verbose output to ensure methods for suppressing all forms of output are available.
## [0.1.25] - 2024-07-23
### Fixed
- Fixed test 1.3.1 as notification window for password expiration is no longer required.
## [0.1.24] - 2024-07-07
### Added
- New private function `Get-AuditMailboxDetail` for 6.1.2 and 6.1.3 tests to get the action details for the test.
### Changed
- Changed `Get-Action` function to include both dictionaries.
### Fixed
- Fixed Test 1.3.3 to be the simpler version of the test while including output to check for current users sharing calendars.
- Safe Attachments logic and added `$DomainName` as input to 2.1.4 to test main policy.
### Docs
- Updated `about_M365FoundationsCISReport` help file with new functions and changes.
- Updated `Invoke-M365SecurityAudit` help file with examples.
- Updated `Export-M365SecurityAudit` help file with examples.
## [0.1.23] - 2024-07-02
# Fixed # Fixed
- SPO tests formatting and output. - SPO tests formatting and output.

View File

@@ -1,5 +1,5 @@
# M365FoundationsCISReport Module # M365FoundationsCISReport Module
[![PSScriptAnalyzer](https://github.com/CriticalSolutionsNetwork/M365FoundationsCISReport/actions/workflows/powershell.yml/badge.svg)](https://github.com/CriticalSolutionsNetwork/M365FoundationsCISReport/actions/workflows/powershell.yml)
## License ## License
This PowerShell module is based on CIS benchmarks and is distributed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This means: This PowerShell module is based on CIS benchmarks and is distributed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This means:
@@ -11,83 +11,86 @@ This PowerShell module is based on CIS benchmarks and is distributed under the C
For full license details, please visit [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en). For full license details, please visit [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en).
[Register for and download CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks) [Register for and download CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks)
# Table of Contents
1. [Invoke-M365SecurityAudit](#Invoke-M365SecurityAudit)
2. [Export-M365SecurityAuditTable](#Export-M365SecurityAuditTable)
3. [Get-AdminRoleUserLicense](#Get-AdminRoleUserLicense)
4. [Get-MFAStatus](#Get-MFAStatus)
5. [Grant-M365SecurityAuditConsent](#Grant-M365SecurityAuditConsent)
6. [New-M365SecurityAuditAuthObject](#New-M365SecurityAuditAuthObject)
7. [Remove-RowsWithEmptyCSVStatus](#Remove-RowsWithEmptyCSVStatus)
8. [Sync-CISExcelAndCsvData](#Sync-CISExcelAndCsvData)
## Module Dependencies
The `M365FoundationsCISReport` module relies on several other PowerShell modules to perform its operations. The default run ensures these modules are installed with the specified versions. Use -NoModuleCheck to skip this step if you have installed the required modules previously and would like to suppress any output for automated runs.
### Required Modules for Audit Functions
Default modules used for audit functions:
- **ExchangeOnlineManagement**
- Required Version: `3.3.0`
- **Microsoft.Graph**
- Required Version: `2.4.0`
- **PnP.PowerShell** (Optional, if PnP App authentication is used for SharePoint Online)
- Required Version: `2.5.0`
- **Microsoft.Online.SharePoint.PowerShell** (If PnP authentication is not used (Default) )
- Required Version: `16.0.24009.12000`
- **MicrosoftTeams**
- Required Version: `5.5.0`
- **ImportExcel** (If importing or exporting Excel files)
- Required Version: `7.8.9`
# EXAMPLES
## Invoke-M365SecurityAudit
### Synopsis
Invokes a security audit for Microsoft 365 environments.
### Syntax
```powershell ```powershell
# 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"
# Suppressed output for automated runs
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -NoModuleCheck -NoModuleCheck -DoNotConfirmConnections -Confirm:$false
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>] # Example 2: Exporting a security audit and it's nested tables to zipped CSV files
Export-M365SecurityAuditTable -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests -ExportNestedTables
# Output Ex: 2024.07.07_14.55.55_M365FoundationsAudit_368B2E2F.zip
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-ELevel <String>] [-ProfileLevel <String>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>] # Example 3: Retrieving licenses for users in administrative roles
Get-AdminRoleUserLicense
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-IncludeIG1] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>] # Example 4: Getting MFA status of users
Get-MFAStatus -UserId "user@domain.com"
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-IncludeIG2] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>]
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-IncludeIG3] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>]
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-IncludeRecommendation <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>]
Invoke-M365SecurityAudit -TenantAdminUrl <String> -DomainName <String> [-SkipRecommendation <String[]>] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-WhatIf] [-Confirm] [<CommonParameters>]
# 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'
# Example 8: (PowerShell 7.x Only) Creating a new authentication object for the security audit for app-based authentication.
$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"
``` ```
### Parameters
| Name | Alias | Description | Required? | Pipeline Input | Default Value |
| - | - | - | - | - | - |
| <nobr>TenantAdminUrl</nobr> | | The URL of the tenant admin. This parameter is mandatory. | true | false | |
| <nobr>DomainName</nobr> | | The domain name of the Microsoft 365 environment. This parameter is mandatory. | true | false | |
| <nobr>ELevel</nobr> | | Specifies the E-Level \(E3 or E5\) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter. | false | false | |
| <nobr>ProfileLevel</nobr> | | Specifies the profile level \(L1 or L2\) for the audit. This parameter is optional and can be combined with the ELevel parameter. | false | false | |
| <nobr>IncludeIG1</nobr> | | If specified, includes tests where IG1 is true. | false | false | False |
| <nobr>IncludeIG2</nobr> | | If specified, includes tests where IG2 is true. | false | false | False |
| <nobr>IncludeIG3</nobr> | | If specified, includes tests where IG3 is true. | false | false | False |
| <nobr>IncludeRecommendation</nobr> | | Specifies specific recommendations to include in the audit. Accepts an array of recommendation numbers. | false | false | |
| <nobr>SkipRecommendation</nobr> | | Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers. | false | false | |
| <nobr>DoNotConnect</nobr> | | If specified, the cmdlet will not establish a connection to Microsoft 365 services. | false | false | False |
| <nobr>DoNotDisconnect</nobr> | | If specified, the cmdlet will not disconnect from Microsoft 365 services after execution. | false | false | False |
| <nobr>NoModuleCheck</nobr> | | If specified, the cmdlet will not check for the presence of required modules. | false | false | False |
| <nobr>WhatIf</nobr> | wi | | false | false | |
| <nobr>Confirm</nobr> | cf | | false | false | |
### Inputs
- None. You cannot pipe objects to Invoke-M365SecurityAudit.
### Outputs # NOTE
- CISAuditResult\\[\] The cmdlet returns an array of CISAuditResult objects representing the results of the security audit. 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.
### Note # TROUBLESHOOTING NOTE
This module is based on CIS benchmarks and is governed by the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. For more details, visit: https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en 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.
### Examples # SEE ALSO
**EXAMPLE 1** - [CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks/)
```powershell - [Microsoft 365 Security Documentation](https://docs.microsoft.com/en-us/microsoft-365/security/)
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ELevel "E5" -ProfileLevel "L1" - [PowerShell Documentation](https://docs.microsoft.com/en-us/powershell/)
```
Performs a security audit for the E5 level and L1 profile in the specified Microsoft 365 environment.
**EXAMPLE 2**
```powershell
Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -IncludeIG1
```
Performs an audit including all tests where IG1 is true.
**EXAMPLE 3**
```powershell
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 4**
```powershell
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com"
PS> $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation
```
Captures the audit results into a variable and exports them to a CSV file.
### Links
- [Online Version: [GitHub Repository URL]](#Online Version: [GitHub Repository URL])

BIN
README.md

Binary file not shown.

Binary file not shown.

View File

@@ -15,24 +15,27 @@ Exports M365 security audit results to a CSV file or outputs a specific test res
### OutputObjectFromAuditResultsSingle ### OutputObjectFromAuditResultsSingle
``` ```
Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [-OutputTestNumber] <String> Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [-OutputTestNumber] <String>
[<CommonParameters>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### ExportAllResultsFromAuditResults ### ExportAllResultsFromAuditResults
``` ```
Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [-ExportAllTests] -ExportPath <String> Export-M365SecurityAuditTable [-AuditResults] <CISAuditResult[]> [-ExportNestedTables] -ExportPath <String>
[-ExportOriginalTests] [-ExportToExcel] [<CommonParameters>] [-ExportOriginalTests] [-ExportToExcel] [-Prefix <String>] [-ProgressAction <ActionPreference>] [-WhatIf]
[-Confirm] [<CommonParameters>]
``` ```
### OutputObjectFromCsvSingle ### OutputObjectFromCsvSingle
``` ```
Export-M365SecurityAuditTable [-CsvPath] <String> [-OutputTestNumber] <String> [<CommonParameters>] Export-M365SecurityAuditTable [-CsvPath] <String> [-OutputTestNumber] <String>
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### ExportAllResultsFromCsv ### ExportAllResultsFromCsv
``` ```
Export-M365SecurityAuditTable [-CsvPath] <String> [-ExportAllTests] -ExportPath <String> [-ExportOriginalTests] Export-M365SecurityAuditTable [-CsvPath] <String> [-ExportNestedTables] -ExportPath <String>
[-ExportToExcel] [<CommonParameters>] [-ExportOriginalTests] [-ExportToExcel] [-Prefix <String>] [-ProgressAction <ActionPreference>] [-WhatIf]
[-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -125,8 +128,8 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ExportAllTests ### -ExportNestedTables
Switch to export all test results. Switch to export all test results. When specified, all test results are exported to the specified path.
```yaml ```yaml
Type: SwitchParameter Type: SwitchParameter
@@ -163,7 +166,7 @@ Type: SwitchParameter
Parameter Sets: ExportAllResultsFromAuditResults, ExportAllResultsFromCsv Parameter Sets: ExportAllResultsFromAuditResults, ExportAllResultsFromCsv
Aliases: Aliases:
Required: True Required: False
Position: Named Position: Named
Default value: False Default value: False
Accept pipeline input: False Accept pipeline input: False
@@ -185,6 +188,67 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -Prefix
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.
```yaml
Type: String
Parameter Sets: ExportAllResultsFromAuditResults, ExportAllResultsFromCsv
Aliases:
Required: False
Position: Named
Default value: Corp
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -1,4 +1,4 @@
--- ---
external help file: M365FoundationsCISReport-help.xml external help file: M365FoundationsCISReport-help.xml
Module Name: M365FoundationsCISReport Module Name: M365FoundationsCISReport
online version: https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Get-AdminRoleUserLicense online version: https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Get-AdminRoleUserLicense
@@ -13,7 +13,7 @@ Retrieves user licenses and roles for administrative accounts from Microsoft 365
## SYNTAX ## SYNTAX
``` ```
Get-AdminRoleUserLicense [-SkipGraphConnection] [<CommonParameters>] Get-AdminRoleUserLicense [-SkipGraphConnection] [-ProgressAction <ActionPreference>] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -54,6 +54,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -13,7 +13,8 @@ Retrieves the MFA (Multi-Factor Authentication) status for Azure Active Director
## SYNTAX ## SYNTAX
``` ```
Get-MFAStatus [[-UserId] <String>] [-SkipMSOLConnectionChecks] [<CommonParameters>] Get-MFAStatus [[-UserId] <String>] [-SkipMSOLConnectionChecks] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -67,6 +68,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -14,7 +14,8 @@ Grants Microsoft Graph permissions for an auditor.
``` ```
Grant-M365SecurityAuditConsent [-UserPrincipalNameForConsent] <String> [-SkipGraphConnection] Grant-M365SecurityAuditConsent [-UserPrincipalNameForConsent] <String> [-SkipGraphConnection]
[-SkipModuleCheck] [-SuppressRevertOutput] [-DoNotDisconnect] [-WhatIf] [-Confirm] [<CommonParameters>] [-SkipModuleCheck] [-SuppressRevertOutput] [-DoNotDisconnect] [-ProgressAction <ActionPreference>] [-WhatIf]
[-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -146,6 +147,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -16,14 +16,16 @@ Invokes a security audit for Microsoft 365 environments.
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>]
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### ELevelFilter ### ELevelFilter
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELevel <String> Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELevel <String>
-ProfileLevel <String> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] -ProfileLevel <String> [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>]
[-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [-DoNotConnect] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections]
[-AuthParams <CISAuthenticationParameters>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
[<CommonParameters>] [<CommonParameters>]
``` ```
@@ -31,35 +33,40 @@ Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -ELev
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG1] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG1]
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### IG2Filter ### IG2Filter
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG2] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG2]
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### IG3Filter ### IG3Filter
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG3] Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] [-IncludeIG3]
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### RecFilter ### RecFilter
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeRecommendation <String[]> Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -IncludeRecommendation <String[]>
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
### SkipRecFilter ### SkipRecFilter
``` ```
Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -SkipRecommendation <String[]> Invoke-M365SecurityAudit [-TenantAdminUrl <String>] [-DomainName <String>] -SkipRecommendation <String[]>
[-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect] [-ApprovedCloudStorageProviders <String[]>] [-ApprovedFederatedDomains <String[]>] [-DoNotConnect]
[-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-WhatIf] [-Confirm] [<CommonParameters>] [-DoNotDisconnect] [-NoModuleCheck] [-DoNotConfirmConnections] [-AuthParams <CISAuthenticationParameters>]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -395,6 +402,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -AuthParams
Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.
```yaml
Type: CISAuthenticationParameters
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf ### -WhatIf
Shows what would happen if the cmdlet runs. Shows what would happen if the cmdlet runs.
The cmdlet is not run. The cmdlet is not run.
@@ -426,6 +448,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -26,6 +26,9 @@ Grants Microsoft Graph permissions for an auditor.
### [Invoke-M365SecurityAudit](Invoke-M365SecurityAudit) ### [Invoke-M365SecurityAudit](Invoke-M365SecurityAudit)
Invokes a security audit for Microsoft 365 environments. Invokes a security audit for Microsoft 365 environments.
### [New-M365SecurityAuditAuthObject](New-M365SecurityAuditAuthObject)
Creates a new CISAuthenticationParameters object for Microsoft 365 authentication.
### [Remove-RowsWithEmptyCSVStatus](Remove-RowsWithEmptyCSVStatus) ### [Remove-RowsWithEmptyCSVStatus](Remove-RowsWithEmptyCSVStatus)
Removes rows from an Excel worksheet where the 'CSV_Status' column is empty and saves the result to a new file. Removes rows from an Excel worksheet where the 'CSV_Status' column is empty and saves the result to a new file.

View File

@@ -0,0 +1,149 @@
---
external help file: M365FoundationsCISReport-help.xml
Module Name: M365FoundationsCISReport
online version:
schema: 2.0.0
---
# New-M365SecurityAuditAuthObject
## SYNOPSIS
Creates a new CISAuthenticationParameters object for Microsoft 365 authentication.
## SYNTAX
```
New-M365SecurityAuditAuthObject [-ClientCertThumbPrint] <String> [-ClientId] <String> [-TenantId] <String>
[-OnMicrosoftUrl] <String> [-SpAdminUrl] <String> [-ProgressAction <ActionPreference>] [<CommonParameters>]
```
## DESCRIPTION
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.
## EXAMPLES
### EXAMPLE 1
```
$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.
```
## PARAMETERS
### -ClientCertThumbPrint
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.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ClientId
The Client ID (Application ID) of the Azure AD application.
It must be a valid GUID format.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -TenantId
The Tenant ID of the Azure AD directory.
It must be a valid GUID format representing your Microsoft 365 tenant.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -OnMicrosoftUrl
The URL of your onmicrosoft.com domain.
It should be in the format 'example.onmicrosoft.com'.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SpAdminUrl
The SharePoint admin URL, which should end with '-admin.sharepoint.com'.
This URL is used for connecting to SharePoint Online.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### None. You cannot pipe objects to this function.
## OUTPUTS
### CISAuthenticationParameters
### The function returns an instance of the CISAuthenticationParameters class containing the authentication details.
## NOTES
Requires PowerShell 7.0 or later.
## RELATED LINKS

View File

@@ -1,4 +1,4 @@
--- ---
external help file: M365FoundationsCISReport-help.xml external help file: M365FoundationsCISReport-help.xml
Module Name: M365FoundationsCISReport Module Name: M365FoundationsCISReport
online version: online version:
@@ -13,7 +13,8 @@ Removes rows from an Excel worksheet where the 'CSV_Status' column is empty and
## SYNTAX ## SYNTAX
``` ```
Remove-RowsWithEmptyCSVStatus [-FilePath] <String> [-WorksheetName] <String> [<CommonParameters>] Remove-RowsWithEmptyCSVStatus [-FilePath] <String> [-WorksheetName] <String>
[-ProgressAction <ActionPreference>] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -60,6 +61,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -14,7 +14,7 @@ Synchronizes and updates data in an Excel worksheet with new information from a
``` ```
Sync-CISExcelAndCsvData [[-ExcelPath] <String>] [[-CsvPath] <String>] [[-SheetName] <String>] Sync-CISExcelAndCsvData [[-ExcelPath] <String>] [[-CsvPath] <String>] [[-SheetName] <String>]
[<CommonParameters>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@@ -80,6 +80,21 @@ Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters ### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

View File

@@ -18,9 +18,11 @@ The module includes functionality to synchronize audit results with CIS benchmar
```powershell ```powershell
# Example 1: Performing a security audit based on CIS benchmarks # 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"
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ApprovedCloudStorageProviders "DropBox" -ApprovedFederatedDomains "northwind.com"
# Example 2: Exporting a security audit table to a CSV file # Example 2: Exporting a security audit and it's nested tables to zipped CSV files
Export-M365SecurityAuditTable -ExportAllTests -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests 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 # Example 3: Retrieving licenses for users in administrative roles
Get-AdminRoleUserLicense Get-AdminRoleUserLicense
@@ -36,6 +38,14 @@ Sync-CISExcelAndCsvData -ExcelPath "path\to\excel.xlsx" -CsvPath "path\to\data.c
# Example 7: Granting Microsoft Graph permissions to the auditor # Example 7: Granting Microsoft Graph permissions to the auditor
Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent 'user@example.com' Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent 'user@example.com'
# Example 8: (PowerShell 7.x Only) Creating a new authentication object for the security audit for app-based authentication.
$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"
``` ```
# NOTE # NOTE

View File

@@ -1,10 +1,11 @@
Import-Module .\output\module\M365FoundationsCISReport\*\*.psd1 Import-Module .\output\module\M365FoundationsCISReport\*\*.psd1
. .\source\Classes\CISAuditResult.ps1
.\helpers\psDoc-master\src\psDoc.ps1 -moduleName M365FoundationsCISReport -outputDir docs -template ".\helpers\psDoc-master\src\out-html-template.ps1" .\helpers\psDoc-master\src\psDoc.ps1 -moduleName M365FoundationsCISReport -outputDir docs -template ".\helpers\psDoc-master\src\out-html-template.ps1"
.\helpers\psDoc-master\src\psDoc.ps1 -moduleName M365FoundationsCISReport -outputDir ".\" -template ".\helpers\psDoc-master\src\out-markdown-template.ps1" -fileName ".\README.md" .\helpers\psDoc-master\src\psDoc.ps1 -moduleName M365FoundationsCISReport -outputDir ".\" -template ".\helpers\psDoc-master\src\out-markdown-template.ps1" -fileName ".\README.md"
<# <#
$ver = "v0.1.22" $ver = "v0.1.26"
git checkout main git checkout main
git pull origin main git pull origin main
git tag -a $ver -m "Release version $ver refactor Update" git tag -a $ver -m "Release version $ver refactor Update"

View File

@@ -0,0 +1,43 @@
class CISAuthenticationParameters {
[string]$ClientCertThumbPrint
[string]$ClientId
[string]$TenantId
[string]$OnMicrosoftUrl
[string]$SpAdminUrl
# Constructor with validation
CISAuthenticationParameters(
[string]$ClientCertThumbPrint,
[string]$ClientId,
[string]$TenantId,
[string]$OnMicrosoftUrl,
[string]$SpAdminUrl
) {
# Validate ClientCertThumbPrint
if (-not $ClientCertThumbPrint -or $ClientCertThumbPrint.Length -ne 40 -or $ClientCertThumbPrint -notmatch '^[0-9a-fA-F]{40}$') {
throw [ArgumentException]::new("ClientCertThumbPrint must be a 40-character hexadecimal string.")
}
# Validate ClientId
if (-not $ClientId -or $ClientId -notmatch '^[0-9a-fA-F\-]{36}$') {
throw [ArgumentException]::new("ClientId must be a valid GUID in the format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.")
}
# Validate TenantId
if (-not $TenantId -or $TenantId -notmatch '^[0-9a-fA-F\-]{36}$') {
throw [ArgumentException]::new("TenantId must be a valid GUID in the format 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.")
}
# Validate OnMicrosoftUrl
if (-not $OnMicrosoftUrl -or $OnMicrosoftUrl -notmatch '^[a-zA-Z0-9]+\.onmicrosoft\.com$') {
throw [ArgumentException]::new("OnMicrosoftUrl must be in the format 'example.onmicrosoft.com'.")
}
# Validate SpAdminUrl
if (-not $SpAdminUrl -or $SpAdminUrl -notmatch '^https:\/\/[a-zA-Z0-9\-]+\-admin\.sharepoint\.com$') {
throw [ArgumentException]::new("SpAdminUrl must be in the format 'https://[name]-admin.sharepoint.com'.")
}
# Assign validated properties
$this.ClientCertThumbPrint = $ClientCertThumbPrint
$this.ClientId = $ClientId
$this.TenantId = $TenantId
$this.OnMicrosoftUrl = $OnMicrosoftUrl
$this.SpAdminUrl = $SpAdminUrl
}
}

View File

@@ -33,7 +33,7 @@ Copyright = '(c) 2024 Douglas S. Rios (DrIOSx). All rights reserved.'
Description = 'Automated assessment of 50 CIS 365 Foundations v3.0.0 benchmark.' Description = 'Automated assessment of 50 CIS 365 Foundations v3.0.0 benchmark.'
# Minimum version of the Windows PowerShell engine required by this module # Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0' # PowerShellVersion = '5.1'
# Name of the Windows PowerShell host required by this module # Name of the Windows PowerShell host required by this module
# PowerShellHostName = '' # PowerShellHostName = ''
@@ -51,7 +51,7 @@ PowerShellVersion = '5.0'
# ProcessorArchitecture = '' # ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module # Modules that must be imported into the global environment prior to importing this module
RequiredModules = @() # RequiredModules = @()
# Assemblies that must be loaded prior to importing this module # Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @() # RequiredAssemblies = @()

View File

@@ -1,37 +1,40 @@
function Assert-ModuleAvailability { function Assert-ModuleAvailability {
[CmdletBinding()]
[OutputType([void]) ] [OutputType([void]) ]
param( param(
[string]$ModuleName, [string]$ModuleName,
[string]$RequiredVersion, [string]$RequiredVersion,
[string[]]$SubModules = @() [string[]]$SubModules = @()
) )
process {
try { try {
$module = Get-Module -ListAvailable -Name $ModuleName | Where-Object { $_.Version -ge [version]$RequiredVersion } $module = Get-Module -ListAvailable -Name $ModuleName | Where-Object { $_.Version -ge [version]$RequiredVersion }
if ($null -eq $module) { if ($null -eq $module) {
Write-Host "Installing $ModuleName module..." -ForegroundColor Yellow Write-Verbose "Installing $ModuleName module..."
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force -AllowClobber -Scope CurrentUser | Out-Null Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force -AllowClobber -Scope CurrentUser | Out-Null
} }
elseif ($module.Version -lt [version]$RequiredVersion) { elseif ($module.Version -lt [version]$RequiredVersion) {
Write-Host "Updating $ModuleName module to required version..." -ForegroundColor Yellow Write-Verbose "Updating $ModuleName module to required version..."
Update-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force | Out-Null Update-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force | Out-Null
} }
else { else {
Write-Host "$ModuleName module is already at required version or newer." -ForegroundColor Gray Write-Verbose "$ModuleName module is already at required version or newer."
} }
if ($SubModules.Count -gt 0) { if ($SubModules.Count -gt 0) {
foreach ($subModule in $SubModules) { foreach ($subModule in $SubModules) {
Write-Host "Importing submodule $ModuleName.$subModule..." -ForegroundColor DarkGray Write-Verbose "Importing submodule $ModuleName.$subModule..."
Import-Module -Name "$ModuleName.$subModule" -RequiredVersion $RequiredVersion -ErrorAction Stop | Out-Null Get-Module "$ModuleName.$subModule" | Import-Module -RequiredVersion $RequiredVersion -ErrorAction Stop | Out-Null
} }
} else { }
Write-Host "Importing module $ModuleName..." -ForegroundColor DarkGray else {
Write-Verbose "Importing module $ModuleName..."
Import-Module -Name $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null Import-Module -Name $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null
} }
} }
catch { catch {
Write-Warning "An error occurred with module $ModuleName`: $_" throw "Assert-ModuleAvailability:`n$_"
} }
}
} }

View File

@@ -2,38 +2,42 @@ function Connect-M365Suite {
[OutputType([void])] [OutputType([void])]
[CmdletBinding()] [CmdletBinding()]
param ( param (
[Parameter(Mandatory = $false)] [Parameter(
Mandatory = $false
)]
[string]$TenantAdminUrl, [string]$TenantAdminUrl,
[Parameter(
[Parameter(Mandatory)] Mandatory = $false
)]
[CISAuthenticationParameters]$AuthParams, # Custom authentication parameters
[Parameter(
Mandatory
)]
[string[]]$RequiredConnections, [string[]]$RequiredConnections,
[Parameter(
[Parameter(Mandatory = $false)] Mandatory = $false
)]
[switch]$SkipConfirmation [switch]$SkipConfirmation
) )
if (!$SkipConfirmation) {
$VerbosePreference = "Continue"
}
else {
$VerbosePreference = "SilentlyContinue" $VerbosePreference = "SilentlyContinue"
}
$tenantInfo = @() $tenantInfo = @()
$connectedServices = @() $connectedServices = @()
try { try {
if ($RequiredConnections -contains "AzureAD" -or $RequiredConnections -contains "AzureAD | EXO" -or $RequiredConnections -contains "AzureAD | EXO | Microsoft Graph") {
Write-Host "Connecting to Azure Active Directory..." -ForegroundColor Yellow
Connect-AzureAD -WarningAction SilentlyContinue | Out-Null
$tenantDetails = Get-AzureADTenantDetail -WarningAction SilentlyContinue
$tenantInfo += [PSCustomObject]@{
Service = "Azure Active Directory"
TenantName = $tenantDetails.DisplayName
TenantID = $tenantDetails.ObjectId
}
$connectedServices += "AzureAD"
Write-Host "Successfully connected to Azure Active Directory." -ForegroundColor Green
}
if ($RequiredConnections -contains "Microsoft Graph" -or $RequiredConnections -contains "EXO | Microsoft Graph") { if ($RequiredConnections -contains "Microsoft Graph" -or $RequiredConnections -contains "EXO | Microsoft Graph") {
Write-Host "Connecting to Microsoft Graph with scopes: Directory.Read.All, Domain.Read.All, Policy.Read.All, Organization.Read.All" -ForegroundColor Yellow Write-Verbose "Connecting to Microsoft Graph"
try { if ($AuthParams) {
# Use application-based authentication
Connect-MgGraph -CertificateThumbprint $AuthParams.ClientCertThumbPrint -AppId $AuthParams.ClientId -TenantId $AuthParams.TenantId -NoWelcome | Out-Null
}
else {
# Use interactive authentication with scopes
Connect-MgGraph -Scopes "Directory.Read.All", "Domain.Read.All", "Policy.Read.All", "Organization.Read.All" -NoWelcome | Out-Null Connect-MgGraph -Scopes "Directory.Read.All", "Domain.Read.All", "Policy.Read.All", "Organization.Read.All" -NoWelcome | Out-Null
}
$graphOrgDetails = Get-MgOrganization $graphOrgDetails = Get-MgOrganization
$tenantInfo += [PSCustomObject]@{ $tenantInfo += [PSCustomObject]@{
Service = "Microsoft Graph" Service = "Microsoft Graph"
@@ -41,25 +45,18 @@ function Connect-M365Suite {
TenantID = $graphOrgDetails.Id TenantID = $graphOrgDetails.Id
} }
$connectedServices += "Microsoft Graph" $connectedServices += "Microsoft Graph"
Write-Host "Successfully connected to Microsoft Graph with specified scopes." -ForegroundColor Green Write-Verbose "Successfully connected to Microsoft Graph.`n"
} }
catch {
Write-Host "Failed to connect to MgGraph, attempting device auth." -ForegroundColor Yellow
Connect-MgGraph -Scopes "Directory.Read.All", "Domain.Read.All", "Policy.Read.All", "Organization.Read.All" -UseDeviceCode -NoWelcome | Out-Null
$graphOrgDetails = Get-MgOrganization
$tenantInfo += [PSCustomObject]@{
Service = "Microsoft Graph"
TenantName = $graphOrgDetails.DisplayName
TenantID = $graphOrgDetails.Id
}
$connectedServices += "Microsoft Graph"
Write-Host "Successfully connected to Microsoft Graph with specified scopes." -ForegroundColor Green
}
}
if ($RequiredConnections -contains "EXO" -or $RequiredConnections -contains "AzureAD | EXO" -or $RequiredConnections -contains "Microsoft Teams | EXO" -or $RequiredConnections -contains "EXO | Microsoft Graph") { if ($RequiredConnections -contains "EXO" -or $RequiredConnections -contains "AzureAD | EXO" -or $RequiredConnections -contains "Microsoft Teams | EXO" -or $RequiredConnections -contains "EXO | Microsoft Graph") {
Write-Host "Connecting to Exchange Online..." -ForegroundColor Yellow Write-Verbose "Connecting to Exchange Online..."
if ($AuthParams) {
# Use application-based authentication
Connect-ExchangeOnline -AppId $AuthParams.ClientId -CertificateThumbprint $AuthParams.ClientCertThumbPrint -Organization $AuthParams.OnMicrosoftUrl -ShowBanner:$false | Out-Null
}
else {
# Use interactive authentication
Connect-ExchangeOnline -ShowBanner:$false | Out-Null Connect-ExchangeOnline -ShowBanner:$false | Out-Null
}
$exoTenant = (Get-OrganizationConfig).Identity $exoTenant = (Get-OrganizationConfig).Identity
$tenantInfo += [PSCustomObject]@{ $tenantInfo += [PSCustomObject]@{
Service = "Exchange Online" Service = "Exchange Online"
@@ -67,25 +64,44 @@ function Connect-M365Suite {
TenantID = "N/A" TenantID = "N/A"
} }
$connectedServices += "EXO" $connectedServices += "EXO"
Write-Host "Successfully connected to Exchange Online." -ForegroundColor Green Write-Verbose "Successfully connected to Exchange Online.`n"
} }
if ($RequiredConnections -contains "SPO") { if ($RequiredConnections -contains "SPO") {
Write-Host "Connecting to SharePoint Online..." -ForegroundColor Yellow Write-Verbose "Connecting to SharePoint Online..."
if ($AuthParams) {
# Use application-based authentication
Connect-PnPOnline -Url $AuthParams.SpAdminUrl -ClientId $AuthParams.ClientId -Tenant $AuthParams.OnMicrosoftUrl -Thumbprint $AuthParams.ClientCertThumbPrint | Out-Null
}
else {
# Use interactive authentication
Connect-SPOService -Url $TenantAdminUrl | Out-Null Connect-SPOService -Url $TenantAdminUrl | Out-Null
}
# Assuming that Get-SPOCrossTenantHostUrl and Get-UrlLine are valid commands in your context
if ($AuthParams) {
$spoContext = Get-PnPSite
$tenantName = $spoContext.Url
}
else {
$spoContext = Get-SPOCrossTenantHostUrl $spoContext = Get-SPOCrossTenantHostUrl
$tenantName = Get-UrlLine -Output $spoContext $tenantName = Get-UrlLine -Output $spoContext
}
$tenantInfo += [PSCustomObject]@{ $tenantInfo += [PSCustomObject]@{
Service = "SharePoint Online" Service = "SharePoint Online"
TenantName = $tenantName TenantName = $tenantName
} }
$connectedServices += "SPO" $connectedServices += "SPO"
Write-Host "Successfully connected to SharePoint Online." -ForegroundColor Green Write-Verbose "Successfully connected to SharePoint Online.`n"
} }
if ($RequiredConnections -contains "Microsoft Teams" -or $RequiredConnections -contains "Microsoft Teams | EXO") { if ($RequiredConnections -contains "Microsoft Teams" -or $RequiredConnections -contains "Microsoft Teams | EXO") {
Write-Host "Connecting to Microsoft Teams..." -ForegroundColor Yellow Write-Verbose "Connecting to Microsoft Teams..."
if ($AuthParams) {
# Use application-based authentication
Connect-MicrosoftTeams -TenantId $AuthParams.TenantId -CertificateThumbprint $AuthParams.ClientCertThumbPrint -ApplicationId $AuthParams.ClientId | Out-Null
}
else {
# Use interactive authentication
Connect-MicrosoftTeams | Out-Null Connect-MicrosoftTeams | Out-Null
}
$teamsTenantDetails = Get-CsTenant $teamsTenantDetails = Get-CsTenant
$tenantInfo += [PSCustomObject]@{ $tenantInfo += [PSCustomObject]@{
Service = "Microsoft Teams" Service = "Microsoft Teams"
@@ -93,30 +109,28 @@ function Connect-M365Suite {
TenantID = $teamsTenantDetails.TenantId TenantID = $teamsTenantDetails.TenantId
} }
$connectedServices += "Microsoft Teams" $connectedServices += "Microsoft Teams"
Write-Host "Successfully connected to Microsoft Teams." -ForegroundColor Green Write-Verbose "Successfully connected to Microsoft Teams.`n"
} }
# Display tenant information and confirm with the user # Display tenant information and confirm with the user
if (-not $SkipConfirmation) { if (-not $SkipConfirmation) {
Write-Host "Connected to the following tenants:" -ForegroundColor Yellow Write-Verbose "Connected to the following tenants:"
foreach ($tenant in $tenantInfo) { foreach ($tenant in $tenantInfo) {
Write-Host "Service: $($tenant.Service)" -ForegroundColor Cyan Write-Verbose "Service: $($tenant.Service)"
Write-Host "Tenant Context: $($tenant.TenantName)`n" -ForegroundColor Green Write-Verbose "Tenant Context: $($tenant.TenantName)`n"
#Write-Host "Tenant ID: $($tenant.TenantID)" #Write-Verbose "Tenant ID: $($tenant.TenantID)"
} }
$confirmation = Read-Host "Do you want to proceed with these connections? (Y/N)" $confirmation = Read-Host "Do you want to proceed with these connections? (Y/N)"
if ($confirmation -notlike 'Y') { if ($confirmation -notLike 'Y') {
Write-Host "Connection setup aborted by user." -ForegroundColor Red Write-Verbose "Connection setup aborted by user."
Disconnect-M365Suite -RequiredConnections $connectedServices Disconnect-M365Suite -RequiredConnections $connectedServices
throw "User aborted connection setup." throw "User aborted connection setup."
} }
} }
} }
catch { catch {
$CatchError = $_
$VerbosePreference = "Continue" $VerbosePreference = "Continue"
Write-Host "There was an error establishing one or more connections: $_" -ForegroundColor Red throw $CatchError
throw $_
} }
$VerbosePreference = "Continue" $VerbosePreference = "Continue"
} }

View File

@@ -8,7 +8,7 @@ function Disconnect-M365Suite {
# Clean up sessions # Clean up sessions
try { try {
if ($RequiredConnections -contains "EXO" -or $RequiredConnections -contains "AzureAD | EXO" -or $RequiredConnections -contains "Microsoft Teams | EXO") { if ($RequiredConnections -contains "EXO" -or $RequiredConnections -contains "AzureAD | EXO" -or $RequiredConnections -contains "Microsoft Teams | EXO") {
Write-Host "Disconnecting from Exchange Online..." -ForegroundColor Green Write-Verbose "Disconnecting from Exchange Online..."
Disconnect-ExchangeOnline -Confirm:$false | Out-Null Disconnect-ExchangeOnline -Confirm:$false | Out-Null
} }
} }
@@ -18,7 +18,7 @@ function Disconnect-M365Suite {
try { try {
if ($RequiredConnections -contains "AzureAD" -or $RequiredConnections -contains "AzureAD | EXO") { if ($RequiredConnections -contains "AzureAD" -or $RequiredConnections -contains "AzureAD | EXO") {
Write-Host "Disconnecting from Azure AD..." -ForegroundColor Green Write-Verbose "Disconnecting from Azure AD..."
Disconnect-AzureAD | Out-Null Disconnect-AzureAD | Out-Null
} }
} }
@@ -28,7 +28,7 @@ function Disconnect-M365Suite {
try { try {
if ($RequiredConnections -contains "Microsoft Graph") { if ($RequiredConnections -contains "Microsoft Graph") {
Write-Host "Disconnecting from Microsoft Graph..." -ForegroundColor Green Write-Verbose "Disconnecting from Microsoft Graph..."
Disconnect-MgGraph | Out-Null Disconnect-MgGraph | Out-Null
} }
} }
@@ -38,23 +38,28 @@ function Disconnect-M365Suite {
try { try {
if ($RequiredConnections -contains "SPO") { if ($RequiredConnections -contains "SPO") {
Write-Host "Disconnecting from SharePoint Online..." -ForegroundColor Green if (($script:PnpAuth)) {
Write-Verbose "Disconnecting from PnPOnline..."
Disconnect-PnPOnline | Out-Null
}
else {
Write-Verbose "Disconnecting from SharePoint Online..."
Disconnect-SPOService | Out-Null Disconnect-SPOService | Out-Null
} }
} }
}
catch { catch {
Write-Warning "Failed to disconnect from SharePoint Online: $_" Write-Warning "Failed to disconnect from SharePoint Online: $_"
} }
try { try {
if ($RequiredConnections -contains "Microsoft Teams" -or $RequiredConnections -contains "Microsoft Teams | EXO") { if ($RequiredConnections -contains "Microsoft Teams" -or $RequiredConnections -contains "Microsoft Teams | EXO") {
Write-Host "Disconnecting from Microsoft Teams..." -ForegroundColor Green Write-Verbose "Disconnecting from Microsoft Teams..."
Disconnect-MicrosoftTeams | Out-Null Disconnect-MicrosoftTeams | Out-Null
} }
} }
catch { catch {
Write-Warning "Failed to disconnect from Microsoft Teams: $_" Write-Warning "Failed to disconnect from Microsoft Teams: $_"
} }
Write-Verbose "All necessary sessions have been disconnected."
Write-Host "All necessary sessions have been disconnected." -ForegroundColor Green
} }

View File

@@ -11,6 +11,12 @@ function Get-Action {
[ValidateSet("Admin", "Delegate", "Owner")] [ValidateSet("Admin", "Delegate", "Owner")]
[string]$ActionType, [string]$ActionType,
[Parameter(Position = 2, Mandatory = $true, ParameterSetName = "ConvertActions")]
[Parameter(Position = 2, Mandatory = $true, ParameterSetName = "ReverseActions")]
[Parameter(Position = 1, Mandatory = $true, ParameterSetName = "GetDictionaries")]
[ValidateSet("6.1.2", "6.1.3")]
[string]$Version = "6.1.2",
[Parameter(Position = 0, ParameterSetName = "ReverseActions")] [Parameter(Position = 0, ParameterSetName = "ReverseActions")]
[string[]]$AbbreviatedActions, [string[]]$AbbreviatedActions,
@@ -20,6 +26,52 @@ function Get-Action {
) )
$Dictionary = @{ $Dictionary = @{
"6.1.2" = @{
AdminActions = @{
ApplyRecord = 'AR'
Copy = 'CP'
Create = 'CR'
FolderBind = 'FB'
HardDelete = 'HD'
Move = 'MV'
MoveToDeletedItems = 'MTDI'
SendAs = 'SA'
SendOnBehalf = 'SOB'
SoftDelete = 'SD'
Update = 'UP'
UpdateCalendarDelegation = 'UCD'
UpdateFolderPermissions = 'UFP'
UpdateInboxRules = 'UIR'
}
DelegateActions = @{
ApplyRecord = 'AR'
Create = 'CR'
FolderBind = 'FB'
HardDelete = 'HD'
Move = 'MV'
MoveToDeletedItems = 'MTDI'
SendAs = 'SA'
SendOnBehalf = 'SOB'
SoftDelete = 'SD'
Update = 'UP'
UpdateFolderPermissions = 'UFP'
UpdateInboxRules = 'UIR'
}
OwnerActions = @{
ApplyRecord = 'AR'
Create = 'CR'
HardDelete = 'HD'
MailboxLogin = 'ML'
Move = 'MV'
MoveToDeletedItems = 'MTDI'
SoftDelete = 'SD'
Update = 'UP'
UpdateCalendarDelegation = 'UCD'
UpdateFolderPermissions = 'UFP'
UpdateInboxRules = 'UIR'
}
}
"6.1.3" = @{
AdminActions = @{ AdminActions = @{
ApplyRecord = 'AR' ApplyRecord = 'AR'
Copy = 'CP' Copy = 'CP'
@@ -69,12 +121,15 @@ function Get-Action {
UpdateInboxRules = 'UIR' UpdateInboxRules = 'UIR'
} }
} }
}
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"GetDictionaries" { "GetDictionaries" {
return $Dictionary return $Dictionary[$Version]
} }
"ConvertActions" { "ConvertActions" {
try {
$Dictionary = $Dictionary[$Version]
$actionDictionary = switch ($ActionType) { $actionDictionary = switch ($ActionType) {
"Admin" { $Dictionary.AdminActions } "Admin" { $Dictionary.AdminActions }
"Delegate" { $Dictionary.DelegateActions } "Delegate" { $Dictionary.DelegateActions }
@@ -89,18 +144,23 @@ function Get-Action {
} }
return $abbreviatedActions return $abbreviatedActions
} }
catch {
throw $_
}
}
"ReverseActions" { "ReverseActions" {
try {
$Dictionary = $Dictionary[$Version]
$reverseDictionary = @{} $reverseDictionary = @{}
$originalDictionary = switch ($ReverseActionType) { $originalDictionary = switch ($ReverseActionType) {
"Admin" { $Dictionary.AdminActions } "Admin" { $Dictionary.AdminActions }
"Delegate" { $Dictionary.DelegateActions } "Delegate" { $Dictionary.DelegateActions }
"Owner" { $Dictionary.OwnerActions } "Owner" { $Dictionary.OwnerActions }
} }
foreach ($key in $originalDictionary.Keys) { foreach ($key in $originalDictionary.Keys) {
$reverseDictionary[$originalDictionary[$key]] = $key $reverseDictionary[$originalDictionary[$key]] = $key
} }
$fullNames = @() $fullNames = @()
foreach ($abbrAction in $AbbreviatedActions) { foreach ($abbrAction in $AbbreviatedActions) {
if ($reverseDictionary.ContainsKey($abbrAction)) { if ($reverseDictionary.ContainsKey($abbrAction)) {
@@ -109,5 +169,9 @@ function Get-Action {
} }
return $fullNames return $fullNames
} }
catch {
throw $_
}
}
} }
} }

View File

@@ -0,0 +1,33 @@
function Get-AuditMailboxDetail {
[cmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[String]$Details,
[Parameter(Mandatory = $true)]
[String]$Version
)
process {
switch ($Version) {
"6.1.2" { [string]$VersionText = "No M365 E3 licenses found."}
"6.1.3" { [string]$VersionText = "No M365 E5 licenses found."}
}
if ($details -ne $VersionText ) {
$csv = $details | ConvertFrom-Csv -Delimiter '|'
}
else {
$csv = $null
}
if ($null -ne $csv) {
foreach ($row in $csv) {
$row.AdminActionsMissing = (Get-Action -AbbreviatedActions $row.AdminActionsMissing.Split(',') -ReverseActionType Admin -Version $Version) -join ','
$row.DelegateActionsMissing = (Get-Action -AbbreviatedActions $row.DelegateActionsMissing.Split(',') -ReverseActionType Delegate -Version $Version ) -join ','
$row.OwnerActionsMissing = (Get-Action -AbbreviatedActions $row.OwnerActionsMissing.Split(',') -ReverseActionType Owner -Version $Version ) -join ','
}
$newObjectDetails = $csv
}
else {
$newObjectDetails = $details
}
return $newObjectDetails
}
}

View File

@@ -46,6 +46,7 @@ function Get-CISExoOutput {
#> #>
} }
process { process {
try {
Write-Verbose "Get-CISExoOutput: Retuning data for Rec: $Rec" Write-Verbose "Get-CISExoOutput: Retuning data for Rec: $Rec"
switch ($Rec) { switch ($Rec) {
'1.2.2' { '1.2.2' {
@@ -87,60 +88,6 @@ function Get-CISExoOutput {
# [psobject[]] # [psobject[]]
return $sharingPolicies return $sharingPolicies
} }
'1.3.3b' {
# $mailboxes Mock Object
<#
$mailboxes = @(
[PSCustomObject]@{
UserPrincipalName = "SMBuser1@domain.com"
ExternalDirectoryObjectId = "123e4567-e89b-12d3-a456-426614174000"
PrimarySmtpAddress = "SMBuser1@domain.com"
PublishEnabled = $False
PublishedCalendarUrl = "https://example.com/calendar/smbuser1"
},
[PSCustomObject]@{
UserPrincipalName = "SMBuser2@domain.com"
ExternalDirectoryObjectId = "987e6543-21ba-12d3-a456-426614174000"
PrimarySmtpAddress = "SMBuser2@domain.com"
PublishEnabled = $False
PublishedCalendarUrl = "https://example.com/calendar/smbuser2"
},
[PSCustomObject]@{
UserPrincipalName = "SMBuser3@domain.com"
ExternalDirectoryObjectId = "abcddcba-98fe-76dc-a456-426614174000"
PrimarySmtpAddress = "SMBuser3@domain.com"
PublishEnabled = $False
PublishedCalendarUrl = "https://example.com/calendar/smbuser3"
}
)
#>
$mailboxes = Get-Mailbox -ResultSize Unlimited
$results = foreach ($mailbox in $mailboxes) {
# Get the name of the default calendar folder (depends on the mailbox's language)
# Return single string Ex: return "Calendar" x 3 in array
$calendarFolder = [string](Get-EXOMailboxFolderStatistics $mailbox.PrimarySmtpAddress -Folderscope Calendar | Where-Object { $_.FolderType -eq 'Calendar' }).Name
Write-Verbose "Calendar folder for $($mailbox.PrimarySmtpAddress): $calendarFolder"
# Get users calendar folder settings for their default Calendar folder
# calendar has the format identity:\<calendar folder name>
$calendar = Get-MailboxCalendarFolder -Identity "$($mailbox.PrimarySmtpAddress):\$calendarFolder"
#Write-Host "Calendar object for $($mailbox.PrimarySmtpAddress): $calendar"
Write-Verbose "Calendar publishing enabled: $($calendar.PublishEnabled)"
# Check if calendar publishing is enabled and create a custom object
if ($calendar.PublishEnabled) {
[PSCustomObject]@{
PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
CalendarFolder = $calendarFolder
PublishEnabled = $calendar.PublishEnabled
PublishedCalendarUrl = $calendar.PublishedCalendarUrl
}
}
}
$calendarDetails = @()
foreach ($calendar in $results) {
$calendarDetails += "Calendar: $($calendar.PrimarySmtpAddress); URL: $($calendar.PublishedCalendarUrl)"
}
return $calendarDetails
}
'1.3.6' { '1.3.6' {
# Test-CustomerLockbox.ps1 # Test-CustomerLockbox.ps1
# Step: Retrieve the organization configuration (Condition C: Pass/Fail) # Step: Retrieve the organization configuration (Condition C: Pass/Fail)
@@ -274,10 +221,11 @@ function Get-CISExoOutput {
) )
#> #>
$safeAttachmentPolicies = Get-SafeAttachmentPolicy -ErrorAction SilentlyContinue | Where-Object { $_.Enable -eq $true } $safeAttachmentPolicies = Get-SafeAttachmentPolicy -ErrorAction SilentlyContinue | Where-Object { $_.Enable -eq $true }
$safeAttachmentRules = Get-SafeAttachmentRule
# [object[]] # [object[]]
return $safeAttachmentPolicies return $safeAttachmentPolicies, $safeAttachmentRules
else { else {
return 1 return 1,1
} }
} }
} }
@@ -532,6 +480,10 @@ function Get-CISExoOutput {
default { throw "No match found for test: $Rec" } default { throw "No match found for test: $Rec" }
} }
} }
catch {
throw "Get-CISExoOutput: `n$_"
}
}
end { end {
Write-Verbose "Retuning data for Rec: $Rec" Write-Verbose "Retuning data for Rec: $Rec"
} }

View File

@@ -34,6 +34,7 @@ function Get-CISMSTeamsOutput {
#> #>
} }
process { process {
try {
Write-Verbose "Get-CISMSTeamsOutput: Retuning data for Rec: $Rec" Write-Verbose "Get-CISMSTeamsOutput: Retuning data for Rec: $Rec"
switch ($Rec) { switch ($Rec) {
'8.1.1' { '8.1.1' {
@@ -326,6 +327,10 @@ function Get-CISMSTeamsOutput {
default { throw "No match found for test: $Rec" } default { throw "No match found for test: $Rec" }
} }
} }
catch {
throw "Get-CISMSTeamsOutput: `n$_"
}
}
end { end {
Write-Verbose "Retuning data for Rec: $Rec" Write-Verbose "Retuning data for Rec: $Rec"
} }

View File

@@ -38,6 +38,7 @@ function Get-CISMgOutput {
#> #>
} }
process { process {
try {
Write-Verbose "Get-CISMgOutput: Retuning data for Rec: $Rec" Write-Verbose "Get-CISMgOutput: Retuning data for Rec: $Rec"
switch ($rec) { switch ($rec) {
'1.1.1' { '1.1.1' {
@@ -59,6 +60,11 @@ function Get-CISMgOutput {
$allGroups = Get-MgGroup -All | Where-Object { $_.Visibility -eq "Public" } | Select-Object DisplayName, Visibility $allGroups = Get-MgGroup -All | Where-Object { $_.Visibility -eq "Public" } | Select-Object DisplayName, Visibility
return $allGroups return $allGroups
} }
'1.2.2' {
# Test-BlockSharedMailboxSignIn.ps1
$users = Get-MgUser
return $users
}
'1.3.1' { '1.3.1' {
# Test-PasswordNeverExpirePolicy.ps1 # Test-PasswordNeverExpirePolicy.ps1
$domains = if ($DomainName) { $domains = if ($DomainName) {
@@ -83,11 +89,11 @@ function Get-CISMgOutput {
} }
'6.1.2' { '6.1.2' {
# Test-MailboxAuditingE3 # Test-MailboxAuditingE3
$tenantSkus = Get-MgSubscribedSku -All $tenantSKUs = Get-MgSubscribedSku -All
$e3SkuPartNumber = "SPE_E3" $e3SkuPartNumber = "SPE_E3"
$founde3Sku = $tenantSkus | Where-Object { $_.SkuPartNumber -eq $e3SkuPartNumber } $foundE3Sku = $tenantSKUs | Where-Object { $_.SkuPartNumber -eq $e3SkuPartNumber }
if ($founde3Sku.Count -ne 0) { if ($foundE3Sku.Count -ne 0) {
$allE3Users = Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq $($founde3Sku.SkuId) )" -All $allE3Users = Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq $($foundE3Sku.SkuId) )" -All
return $allE3Users return $allE3Users
} }
else { else {
@@ -96,11 +102,11 @@ function Get-CISMgOutput {
} }
'6.1.3' { '6.1.3' {
# Test-MailboxAuditingE5 # Test-MailboxAuditingE5
$tenantSkus = Get-MgSubscribedSku -All $tenantSKUs = Get-MgSubscribedSku -All
$e5SkuPartNumber = "SPE_E5" $e5SkuPartNumber = "SPE_E5"
$founde5Sku = $tenantSkus | Where-Object { $_.SkuPartNumber -eq $e5SkuPartNumber } $foundE5Sku = $tenantSKUs | Where-Object { $_.SkuPartNumber -eq $e5SkuPartNumber }
if ($founde5Sku.Count -ne 0) { if ($foundE5Sku.Count -ne 0) {
$allE5Users = Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq $($founde5Sku.SkuId) )" -All $allE5Users = Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq $($foundE5Sku.SkuId) )" -All
return $allE5Users return $allE5Users
} }
else { else {
@@ -110,6 +116,10 @@ function Get-CISMgOutput {
default { throw "No match found for test: $Rec" } default { throw "No match found for test: $Rec" }
} }
} }
catch {
throw "Get-CISMgOutput: `n$_"
}
}
end { end {
Write-Verbose "Retuning data for Rec: $Rec" Write-Verbose "Retuning data for Rec: $Rec"
} }

View File

@@ -1,200 +1,161 @@
<# <#
.SYNOPSIS .SYNOPSIS
This is a sample Private function only visible within the module. Retrieves configuration settings from SharePoint Online or PnP based on the specified recommendation.
.DESCRIPTION .DESCRIPTION
This sample function is not exported to the module and only return the data passed as parameter. The Get-CISSpoOutput function retrieves specific configuration settings from SharePoint Online or PnP based on a recommendation number.
It dynamically switches between using SPO and PnP commands based on the provided authentication context.
.PARAMETER Rec
The recommendation number corresponding to the specific test to be run.
.INPUTS
None. You cannot pipe objects to this function.
.OUTPUTS
PSCustomObject
Returns configuration details for the specified recommendation.
.EXAMPLE .EXAMPLE
$null = Get-CISSpoOutput -PrivateData 'NOTHING TO SEE HERE' PS> Get-CISSpoOutput -Rec '7.2.1'
.PARAMETER PrivateData Retrieves the LegacyAuthProtocolsEnabled property from the SharePoint Online or PnP tenant.
The PrivateData parameter is what will be returned without transformation.
#> #>
function Get-CISSpoOutput { function Get-CISSpoOutput {
[cmdletBinding()] [CmdletBinding()]
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true, HelpMessage = "The recommendation number corresponding to the specific test to be run.")]
[String]$Rec [String]$Rec
) )
begin { begin {
# Begin Block # # Check if PnP should be used
<# $UsePnP = $script:PnpAuth
# Tests # Determine the prefix based on the switch
7.2.1 $prefix = if ($UsePnP) { "PnP" } else { "SPO" }
7.2.2 # Define a hashtable to map the function calls
7.2.3 $commandMap = @{
7.2.4
7.2.5
7.2.6
7.2.7
7.2.9
7.2.10
7.3.1
7.3.2
7.3.4
# Test number array
$testNumbers = @('7.2.1', '7.2.2', '7.2.3', '7.2.4', '7.2.5', '7.2.6', '7.2.7', '7.2.9', '7.2.10', '7.3.1', '7.3.2', '7.3.4')
#>
}
process {
Write-Verbose "Retuning data for Rec: $Rec"
switch ($Rec) {
'7.2.1' {
# Test-ModernAuthSharePoint.ps1 # Test-ModernAuthSharePoint.ps1
# 7.2.1 (L1) Ensure Legacy Authentication Protocols are disabled
# $SPOTenant Mock Object # $SPOTenant Mock Object
<# '7.2.1' = {
$SPOTenant = [PSCustomObject]@{ Invoke-Command {
LegacyAuthProtocolsEnabled = $true & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property LegacyAuthProtocolsEnabled
} }
#>
$SPOTenant = Get-SPOTenant | Select-Object -Property LegacyAuthProtocolsEnabled
return $SPOTenant
}
'7.2.2' {
# Test-SharePointAADB2B.ps1 # Test-SharePointAADB2B.ps1
# 7.2.2 (L1) Ensure SharePoint and OneDrive integration with Azure AD B2B is enabled # 7.2.2 (L1) Ensure SharePoint and OneDrive integration with Azure AD B2B is enabled
# $SPOTenantAzureADB2B Mock Object # $SPOTenantAzureADB2B Mock Object
<# '7.2.2' = {
$SPOTenantAzureADB2B = [PSCustomObject]@{ Invoke-Command {
EnableAzureADB2BIntegration = $false & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property EnableAzureADB2BIntegration
} }
#>
$SPOTenantAzureADB2B = Get-SPOTenant | Select-Object EnableAzureADB2BIntegration
return $SPOTenantAzureADB2B
}
'7.2.3' {
# Test-RestrictExternalSharing.ps1 # Test-RestrictExternalSharing.ps1
# 7.2.3 (L1) Ensure external content sharing is restricted # 7.2.3 (L1) Ensure external content sharing is restricted
# Retrieve the SharingCapability setting for the SharePoint tenant # Retrieve the SharingCapability setting for the SharePoint tenant
# $SPOTenantSharingCapability Mock Object # $SPOTenantSharingCapability Mock Object
<# '7.2.3' = {
$SPOTenantSharingCapability = [PSCustomObject]@{ Invoke-Command {
SharingCapability = "ExternalUserAndGuestSharing" & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property SharingCapability
} }
#>
$SPOTenantSharingCapability = Get-SPOTenant | Select-Object SharingCapability
return $SPOTenantSharingCapability
}
'7.2.4' {
# Test-OneDriveContentRestrictions.ps1 # Test-OneDriveContentRestrictions.ps1
# 7.2.4 (L2) Ensure OneDrive content sharing is restricted # 7.2.4 (L2) Ensure OneDrive content sharing is restricted
# $SPOTenant Mock Object # $SPOTenant Mock Object
<# '7.2.4' = {
$SPOTenant = [PSCustomObject]@{ Invoke-Command {
OneDriveSharingCapability = "ExternalUserAndGuestSharing" if ($prefix -eq "SPO") {
& "$((Get-Command -Name "Get-${prefix}Tenant").Name)" | Select-Object -Property OneDriveSharingCapability
} else {
# Workaround until bugfix in PnP.PowerShell
& "$((Get-Command -Name "Get-${prefix}Tenant").Name)" | Select-Object -Property OneDriveLoopSharingCapability | Select-Object @{Name = "OneDriveSharingCapability"; Expression = { $_.OneDriveLoopSharingCapability }}
}
} }
#>
$SPOTenant = Get-SPOTenant | Select-Object OneDriveSharingCapability
return $SPOTenant
} }
'7.2.5' {
# Test-SharePointGuestsItemSharing.ps1 # Test-SharePointGuestsItemSharing.ps1
# 7.2.5 (L2) Ensure that SharePoint guest users cannot share items they don't own # 7.2.5 (L2) Ensure that SharePoint guest users cannot share items they don't own
# $SPOTenant Mock Object # $SPOTenant Mock Object
<# '7.2.5' = {
$SPOTenant = [PSCustomObject]@{ Invoke-Command {
PreventExternalUsersFromResharing = $false & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property PreventExternalUsersFromResharing
} }
#>
$SPOTenant = Get-SPOTenant | Select-Object PreventExternalUsersFromResharing
return $SPOTenant
}
'7.2.6' {
# Test-SharePointExternalSharingDomains.ps1 # Test-SharePointExternalSharingDomains.ps1
# 7.2.6 (L2) Ensure SharePoint external sharing is managed through domain whitelist/blacklists # 7.2.6 (L2) Ensure SharePoint external sharing is managed through domain whitelist/blacklists
# Add Authorized Domains? # Add Authorized Domains?
# $SPOTenant Mock Object # $SPOTenant Mock Object
<# '7.2.6' = {
$SPOTenant = [PSCustomObject]@{ Invoke-Command {
SharingDomainRestrictionMode = "AllowList" & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
SharingAllowedDomainList = "domain1.com", "domain2.com" } | Select-Object -Property SharingDomainRestrictionMode, SharingAllowedDomainList
} }
#>
$SPOTenant = Get-SPOTenant | Select-Object SharingDomainRestrictionMode, SharingAllowedDomainList
return $SPOTenant
}
'7.2.7' {
# Test-LinkSharingRestrictions.ps1 # Test-LinkSharingRestrictions.ps1
# Retrieve link sharing configuration for SharePoint and OneDrive # Retrieve link sharing configuration for SharePoint and OneDrive
# $SPOTenantLinkSharing Mock Object # $SPOTenantLinkSharing Mock Object
<# '7.2.7' = {
$$SPOTenantLinkSharing = [PSCustomObject]@{ Invoke-Command {
DefaultSharingLinkType = "Direct" & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property DefaultSharingLinkType
} }
#>
$SPOTenantLinkSharing = Get-SPOTenant | Select-Object DefaultSharingLinkType
return $SPOTenantLinkSharing
}
'7.2.9' {
# Test-GuestAccessExpiration.ps1 # Test-GuestAccessExpiration.ps1
# Retrieve SharePoint tenant settings related to guest access expiration # Retrieve SharePoint tenant settings related to guest access expiration
# $SPOTenantGuestAccess Mock Object # $SPOTenantGuestAccess Mock Object
<# '7.2.9' = {
$SPOTenantGuestAccess = [PSCustomObject]@{ Invoke-Command {
ExternalUserExpirationRequired = "$false" & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
ExternalUserExpireInDays = "60" } | Select-Object -Property ExternalUserExpirationRequired, ExternalUserExpireInDays
} }
#>
$SPOTenantGuestAccess = Get-SPOTenant | Select-Object ExternalUserExpirationRequired, ExternalUserExpireInDays
return $SPOTenantGuestAccess
}
'7.2.10' {
# Test-ReauthWithCode.ps1 # Test-ReauthWithCode.ps1
# 7.2.10 (L1) Ensure reauthentication with verification code is restricted # 7.2.10 (L1) Ensure reauthentication with verification code is restricted
# Retrieve reauthentication settings for SharePoint Online # Retrieve reauthentication settings for SharePoint Online
# $SPOTenantReauthentication Mock Object # $SPOTenantReauthentication Mock Object
<# '7.2.10' = {
$SPOTenantReauthentication = [PSCustomObject]@{ Invoke-Command {
EmailAttestationRequired = "$false" & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
EmailAttestationReAuthDays = "30" } | Select-Object -Property EmailAttestationRequired, EmailAttestationReAuthDays
} }
#>
$SPOTenantReauthentication = Get-SPOTenant | Select-Object EmailAttestationRequired, EmailAttestationReAuthDays
return $SPOTenantReauthentication
}
'7.3.1' {
# Test-DisallowInfectedFilesDownload.ps1 # Test-DisallowInfectedFilesDownload.ps1
# Retrieve the SharePoint tenant configuration # Retrieve the SharePoint tenant configuration
# $SPOTenantDisallowInfectedFileDownload Mock Object # $SPOTenantDisallowInfectedFileDownload Mock Object
<# '7.3.1' = {
$SPOTenantDisallowInfectedFileDownload = [PSCustomObject]@{ Invoke-Command {
DisallowInfectedFileDownload = $false & "$((Get-Command -Name "Get-${prefix}Tenant").Name)"
} | Select-Object -Property DisallowInfectedFileDownload
} }
#>
$SPOTenantDisallowInfectedFileDownload = Get-SPOTenant | Select-Object DisallowInfectedFileDownload
return $SPOTenantDisallowInfectedFileDownload
}
'7.3.2' {
# Test-OneDriveSyncRestrictions.ps1 # Test-OneDriveSyncRestrictions.ps1
# Retrieve OneDrive sync client restriction settings # Retrieve OneDrive sync client restriction settings
# Add isHybrid paramter? # Add isHybrid parameter?
# $SPOTenantSyncClientRestriction Mock Object # $SPOTenantSyncClientRestriction Mock Object
<# '7.3.2' = {
$SPOTenantSyncClientRestriction = [PSCustomObject]@{ Invoke-Command {
TenantRestrictionEnabled = $true & "$((Get-Command -Name "Get-${prefix}TenantSyncClientRestriction").Name)"
AllowedDomainList = "786548DD-877B-4760-A749-6B1EFBC1190A", "877564FF-877B-4760-A749-6B1EFBC1190A" } | Select-Object -Property TenantRestrictionEnabled, AllowedDomainList
} }
#>
$SPOTenantSyncClientRestriction = Get-SPOTenantSyncClientRestriction | Select-Object TenantRestrictionEnabled, AllowedDomainList
return $SPOTenantSyncClientRestriction
}
'7.3.4' {
# Test-RestrictCustomScripts.ps1 # Test-RestrictCustomScripts.ps1
# Retrieve all site collections and select necessary properties # Retrieve all site collections and select necessary properties
# $SPOSitesCustomScript Mock Object # $SPOSitesCustomScript Mock Object
<# '7.3.4' = {
$SPOSitesCustomScript = [PSCustomObject]@{ Invoke-Command {
Title = "Site Collection 1" if ($prefix -eq "SPO") {
Url = "https://contoso.sharepoint.com/sites/site1" & "$((Get-Command -Name "Get-${prefix}Site").Name)" -Limit All | Select-Object Title, Url, DenyAddAndCustomizePages
DenyAddAndCustomizePages = "Enabled" } else {
& "$((Get-Command -Name "Get-${prefix}TenantSite").Name)" | Select-Object Title, Url, DenyAddAndCustomizePages
} }
#>
$SPOSitesCustomScript = Get-SPOSite -Limit All | Select-Object Title, Url, DenyAddAndCustomizePages
return $SPOSitesCustomScript
} }
default { throw "No match found for test: $Rec" } }
}
}
process {
try {
Write-Verbose "Returning data for Rec: $Rec"
if ($commandMap.ContainsKey($Rec)) {
# Invoke the script block associated with the command
$result = & $commandMap[$Rec] -ErrorAction Stop
return $result
}
else {
throw "No match found for test: $Rec"
}
}
catch {
throw "Get-CISSpoOutput: `n$_"
} }
} }
end { end {
Write-Verbose "Retuning data for Rec: $Rec" Write-Verbose "Finished processing for Rec: $Rec"
} }
} # end function Get-CISMSTeamsOutput }

View File

@@ -4,21 +4,28 @@ function Get-RequiredModule {
param ( param (
[Parameter(Mandatory = $true, ParameterSetName = 'AuditFunction')] [Parameter(Mandatory = $true, ParameterSetName = 'AuditFunction')]
[switch]$AuditFunction, [switch]$AuditFunction,
[Parameter(Mandatory = $true, ParameterSetName = 'SyncFunction')] [Parameter(Mandatory = $true, ParameterSetName = 'SyncFunction')]
[switch]$SyncFunction [switch]$SyncFunction
) )
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'AuditFunction' { 'AuditFunction' {
if (($script:PnpAuth)) {
return @( return @(
@{ ModuleName = "ExchangeOnlineManagement"; RequiredVersion = "3.3.0"; SubModules = @() }, @{ ModuleName = "ExchangeOnlineManagement"; RequiredVersion = "3.3.0"; SubModules = @() },
@{ ModuleName = "AzureAD"; RequiredVersion = "2.0.2.182"; SubModules = @() }, @{ ModuleName = "Microsoft.Graph"; RequiredVersion = "2.4.0"; SubModules = @("DeviceManagement", "Users", "Identity.DirectoryManagement", "Identity.SignIns") },
@{ ModuleName = "Microsoft.Graph"; RequiredVersion = "2.4.0"; SubModules = @("Groups", "DeviceManagement", "Users", "Identity.DirectoryManagement", "Identity.SignIns") }, @{ ModuleName = "PnP.PowerShell"; RequiredVersion = "2.5.0"; SubModules = @() },
@{ ModuleName = "MicrosoftTeams"; RequiredVersion = "5.5.0"; SubModules = @() }
)
}
else {
return @(
@{ ModuleName = "ExchangeOnlineManagement"; RequiredVersion = "3.3.0"; SubModules = @() },
@{ ModuleName = "Microsoft.Graph"; RequiredVersion = "2.4.0"; SubModules = @("DeviceManagement", "Users", "Identity.DirectoryManagement", "Identity.SignIns") },
@{ ModuleName = "Microsoft.Online.SharePoint.PowerShell"; RequiredVersion = "16.0.24009.12000"; SubModules = @() }, @{ ModuleName = "Microsoft.Online.SharePoint.PowerShell"; RequiredVersion = "16.0.24009.12000"; SubModules = @() },
@{ ModuleName = "MicrosoftTeams"; RequiredVersion = "5.5.0"; SubModules = @() } @{ ModuleName = "MicrosoftTeams"; RequiredVersion = "5.5.0"; SubModules = @() }
) )
} }
}
'SyncFunction' { 'SyncFunction' {
return @( return @(
@{ ModuleName = "ImportExcel"; RequiredVersion = "7.8.9"; SubModules = @() } @{ ModuleName = "ImportExcel"; RequiredVersion = "7.8.9"; SubModules = @() }

View File

@@ -27,7 +27,7 @@ function Get-TestError {
$script:FailedTests.Add([PSCustomObject]@{ Rec = $recnum; Description = $description; Error = $LastError }) $script:FailedTests.Add([PSCustomObject]@{ Rec = $recnum; Description = $description; Error = $LastError })
# Call Initialize-CISAuditResult with error parameters # Call Initialize-CISAuditResult with error parameters
$auditResult = Initialize-CISAuditResult -Rec $recnum -Failure $auditResult = Initialize-CISAuditResult -Rec $recnum -Failure
Write-Verbose "An error occurred during the test: `n$LastError" -Verbose Write-Verbose "An error occurred during the test $recnum`: `n$LastError" -Verbose
return $auditResult return $auditResult
} }

View File

@@ -8,10 +8,7 @@ function Get-UniqueConnection {
$uniqueConnections = @() $uniqueConnections = @()
if ($Connections -contains "AzureAD" -or $Connections -contains "AzureAD | EXO" -or $Connections -contains "AzureAD | EXO | Microsoft Graph") { if ($Connections -contains "Microsoft Graph" -or $Connections -contains "AzureAD | EXO | Microsoft Graph" -or $Connections -contains "EXO | Microsoft Graph") {
$uniqueConnections += "AzureAD"
}
if ($Connections -contains "Microsoft Graph" -or $Connections -contains "AzureAD | EXO | Microsoft Graph") {
$uniqueConnections += "Microsoft Graph" $uniqueConnections += "Microsoft Graph"
} }
if ($Connections -contains "EXO" -or $Connections -contains "AzureAD | EXO" -or $Connections -contains "Microsoft Teams | EXO" -or $Connections -contains "AzureAD | EXO | Microsoft Graph") { if ($Connections -contains "EXO" -or $Connections -contains "AzureAD | EXO" -or $Connections -contains "Microsoft Teams | EXO" -or $Connections -contains "AzureAD | EXO | Microsoft Graph") {

View File

@@ -33,7 +33,7 @@ function Invoke-TestFunction {
return $result return $result
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
$script:FailedTests.Add([PSCustomObject]@{ Test = $functionName; Error = $_ }) $script:FailedTests.Add([PSCustomObject]@{ Test = $functionName; Error = $_ })
# Call Initialize-CISAuditResult with error parameters # Call Initialize-CISAuditResult with error parameters

View File

@@ -18,15 +18,15 @@ function Measure-AuditResult {
$passPercentage = if ($totalTests -eq 0) { 0 } else { [math]::Round(($passedTests / $totalTests) * 100, 2) } $passPercentage = if ($totalTests -eq 0) { 0 } else { [math]::Round(($passedTests / $totalTests) * 100, 2) }
# Display the pass percentage to the user # Display the pass percentage to the user
Write-Host "Audit completed. $passedTests out of $totalTests tests passed." -ForegroundColor Cyan Write-Information "Audit completed. $passedTests out of $totalTests tests passed."
Write-Host "Your passing percentage is $passPercentage%." -ForegroundColor Magenta Write-Information "Your passing percentage is $passPercentage%."
# Display details of failed tests # Display details of failed tests
if ($FailedTests.Count -gt 0) { if ($FailedTests.Count -gt 0) {
Write-Host "The following tests failed to complete:" -ForegroundColor Red Write-Verbose "The following tests failed to complete:"
foreach ($failedTest in $FailedTests) { foreach ($failedTest in $FailedTests) {
Write-Host "Test: $($failedTest.Test)" -ForegroundColor Yellow Write-Verbose "Test: $($failedTest.Test)"
Write-Host "Error: $($failedTest.Error)" -ForegroundColor Yellow Write-Verbose "Error: $($failedTest.Error)"
} }
} }
} }

View File

@@ -11,7 +11,7 @@
The path to a CSV file containing the audit results. This parameter is mandatory when exporting from a CSV file. The path to a CSV file containing the audit results. This parameter is mandatory when exporting from a CSV file.
.PARAMETER OutputTestNumber .PARAMETER OutputTestNumber
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. 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.
.PARAMETER ExportAllTests .PARAMETER ExportNestedTables
Switch to export all test results. When specified, all test results are exported to the specified path. Switch to export all test results. When specified, all test results are exported to the specified path.
.PARAMETER ExportPath .PARAMETER ExportPath
The path where the CSV or Excel files will be exported. This parameter is mandatory when exporting all tests. The path where the CSV or Excel files will be exported. This parameter is mandatory when exporting all tests.
@@ -28,28 +28,28 @@
Export-M365SecurityAuditTable -AuditResults $object -OutputTestNumber 6.1.2 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. # Outputs the result of test number 6.1.2 from the provided audit results as an object.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -ExportAllTests -AuditResults $object -ExportPath "C:\temp" Export-M365SecurityAuditTable -ExportNestedTables -AuditResults $object -ExportPath "C:\temp"
# Exports all audit results to the specified path in CSV format. # Exports all audit results to the specified path in CSV format.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -CsvPath "C:\temp\auditresultstoday1.csv" -OutputTestNumber 6.1.2 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. # Outputs the result of test number 6.1.2 from the CSV file as an object.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -ExportAllTests -CsvPath "C:\temp\auditresultstoday1.csv" -ExportPath "C:\temp" 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. # Exports all audit results from the CSV file to the specified path in CSV format.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -ExportAllTests -AuditResults $object -ExportPath "C:\temp" -ExportOriginalTests 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. # Exports all audit results along with the original test results to the specified path in CSV format.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -ExportAllTests -CsvPath "C:\temp\auditresultstoday1.csv" -ExportPath "C:\temp" -ExportOriginalTests 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. # Exports all audit results from the CSV file along with the original test results to the specified path in CSV format.
.EXAMPLE .EXAMPLE
Export-M365SecurityAuditTable -ExportAllTests -AuditResults $object -ExportPath "C:\temp" -ExportToExcel Export-M365SecurityAuditTable -ExportNestedTables -AuditResults $object -ExportPath "C:\temp" -ExportToExcel
# Exports all audit results to the specified path in Excel format. # Exports all audit results to the specified path in Excel format.
.LINK .LINK
https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Export-M365SecurityAuditTable https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Export-M365SecurityAuditTable
#> #>
function Export-M365SecurityAuditTable { function Export-M365SecurityAuditTable {
[CmdletBinding()] [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
[OutputType([PSCustomObject])] [OutputType([PSCustomObject])]
param ( param (
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = "ExportAllResultsFromAuditResults")] [Parameter(Mandatory = $true, Position = 1, ParameterSetName = "ExportAllResultsFromAuditResults")]
@@ -65,22 +65,31 @@ function Export-M365SecurityAuditTable {
[string]$OutputTestNumber, [string]$OutputTestNumber,
[Parameter(Mandatory = $false, Position = 0, ParameterSetName = "ExportAllResultsFromAuditResults")] [Parameter(Mandatory = $false, Position = 0, ParameterSetName = "ExportAllResultsFromAuditResults")]
[Parameter(Mandatory = $false, Position = 0, ParameterSetName = "ExportAllResultsFromCsv")] [Parameter(Mandatory = $false, Position = 0, ParameterSetName = "ExportAllResultsFromCsv")]
[switch]$ExportAllTests, [switch]$ExportNestedTables,
[Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromAuditResults")] [Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromAuditResults")]
[Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromCsv")] [Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromCsv")]
[string]$ExportPath, [string]$ExportPath,
[Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromAuditResults")] [Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromAuditResults")]
[Parameter(Mandatory = $true, ParameterSetName = "ExportAllResultsFromCsv")] [Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromCsv")]
[switch]$ExportOriginalTests, [switch]$ExportOriginalTests,
[Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromAuditResults")] [Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromAuditResults")]
[Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromCsv")] [Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromCsv")]
[switch]$ExportToExcel [switch]$ExportToExcel,
# Add Prefix to filename after date when outputting to excel or csv.
[Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromAuditResults")]
[Parameter(Mandatory = $false, ParameterSetName = "ExportAllResultsFromCsv")]
# Validate that the count of letters in the prefix is less than 5.
[ValidateLength(0, 5)]
[string]$Prefix = "Corp"
) )
Begin { Begin {
$createdFiles = @() # Initialize an array to keep track of created files $createdFiles = @() # Initialize an array to keep track of created files
if ($ExportToExcel) { if ($ExportToExcel) {
if ($PSCmdlet.ShouldProcess("ImportExcel v7.8.9", "Assert-ModuleAvailability")) {
Assert-ModuleAvailability -ModuleName ImportExcel -RequiredVersion "7.8.9" Assert-ModuleAvailability -ModuleName ImportExcel -RequiredVersion "7.8.9"
} }
}
if ($PSCmdlet.ParameterSetName -like "ExportAllResultsFromCsv" -or $PSCmdlet.ParameterSetName -eq "OutputObjectFromCsvSingle") { if ($PSCmdlet.ParameterSetName -like "ExportAllResultsFromCsv" -or $PSCmdlet.ParameterSetName -eq "OutputObjectFromCsvSingle") {
$AuditResults = Import-Csv -Path $CsvPath | ForEach-Object { $AuditResults = Import-Csv -Path $CsvPath | ForEach-Object {
$params = @{ $params = @{
@@ -93,7 +102,7 @@ function Export-M365SecurityAuditTable {
Initialize-CISAuditResult @params Initialize-CISAuditResult @params
} }
} }
if ($ExportAllTests) { if ($ExportNestedTables) {
$TestNumbers = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4" $TestNumbers = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4"
} }
$results = @() $results = @()
@@ -109,44 +118,12 @@ function Export-M365SecurityAuditTable {
switch ($test) { switch ($test) {
"6.1.2" { "6.1.2" {
$details = $auditResult.Details $details = $auditResult.Details
if ($details -ne "No M365 E3 licenses found.") { $newObjectDetails = Get-AuditMailboxDetail -Details $details -Version '6.1.2'
$csv = $details | ConvertFrom-Csv -Delimiter '|'
}
else {
$csv = $null
}
if ($null -ne $csv) {
foreach ($row in $csv) {
$row.AdminActionsMissing = (Get-Action -AbbreviatedActions $row.AdminActionsMissing.Split(',') -ReverseActionType Admin | Where-Object { $_ -notin @("MailItemsAccessed", "Send") }) -join ','
$row.DelegateActionsMissing = (Get-Action -AbbreviatedActions $row.DelegateActionsMissing.Split(',') -ReverseActionType Delegate | Where-Object { $_ -notin @("MailItemsAccessed") }) -join ','
$row.OwnerActionsMissing = (Get-Action -AbbreviatedActions $row.OwnerActionsMissing.Split(',') -ReverseActionType Owner | Where-Object { $_ -notin @("MailItemsAccessed", "Send") }) -join ','
}
$newObjectDetails = $csv
}
else {
$newObjectDetails = $details
}
$results += [PSCustomObject]@{ TestNumber = $test; Details = $newObjectDetails } $results += [PSCustomObject]@{ TestNumber = $test; Details = $newObjectDetails }
} }
"6.1.3" { "6.1.3" {
$details = $auditResult.Details $details = $auditResult.Details
if ($details -ne "No M365 E5 licenses found.") { $newObjectDetails = Get-AuditMailboxDetail -Details $details -Version '6.1.3'
$csv = $details | ConvertFrom-Csv -Delimiter '|'
}
else {
$csv = $null
}
if ($null -ne $csv) {
foreach ($row in $csv) {
$row.AdminActionsMissing = (Get-Action -AbbreviatedActions $row.AdminActionsMissing.Split(',') -ReverseActionType Admin) -join ','
$row.DelegateActionsMissing = (Get-Action -AbbreviatedActions $row.DelegateActionsMissing.Split(',') -ReverseActionType Delegate) -join ','
$row.OwnerActionsMissing = (Get-Action -AbbreviatedActions $row.OwnerActionsMissing.Split(',') -ReverseActionType Owner) -join ','
}
$newObjectDetails = $csv
}
else {
$newObjectDetails = $details
}
$results += [PSCustomObject]@{ TestNumber = $test; Details = $newObjectDetails } $results += [PSCustomObject]@{ TestNumber = $test; Details = $newObjectDetails }
} }
Default { Default {
@@ -159,6 +136,7 @@ function Export-M365SecurityAuditTable {
} }
End { End {
if ($ExportPath) { if ($ExportPath) {
if ($PSCmdlet.ShouldProcess("Export-M365SecurityAuditTable", "Exporting results to $ExportPath")) {
$timestamp = (Get-Date).ToString("yyyy.MM.dd_HH.mm.ss") $timestamp = (Get-Date).ToString("yyyy.MM.dd_HH.mm.ss")
$exportedTests = @() $exportedTests = @()
foreach ($result in $results) { foreach ($result in $results) {
@@ -166,7 +144,7 @@ function Export-M365SecurityAuditTable {
if ($testDef) { if ($testDef) {
$fileName = "$ExportPath\$($timestamp)_$($result.TestNumber).$($testDef.TestFileName -replace '\.ps1$').csv" $fileName = "$ExportPath\$($timestamp)_$($result.TestNumber).$($testDef.TestFileName -replace '\.ps1$').csv"
if ($result.Details.Count -eq 0) { if ($result.Details.Count -eq 0) {
Write-Information "No results found for test number $($result.TestNumber)." -InformationAction Continue Write-Information "No results found for test number $($result.TestNumber)."
} }
else { else {
if (($result.Details -ne "No M365 E3 licenses found.") -and ($result.Details -ne "No M365 E5 licenses found.")) { if (($result.Details -ne "No M365 E3 licenses found.") -and ($result.Details -ne "No M365 E5 licenses found.")) {
@@ -185,14 +163,14 @@ function Export-M365SecurityAuditTable {
} }
} }
if ($exportedTests.Count -gt 0) { if ($exportedTests.Count -gt 0) {
Write-Information "The following tests were exported: $($exportedTests -join ', ')" -InformationAction Continue Write-Information "The following tests were exported: $($exportedTests -join ', ')"
} }
else { else {
if ($ExportOriginalTests) { if ($ExportOriginalTests) {
Write-Information "Full audit results exported however, none of the following tests had exports: `n1.1.1, 1.3.1, 6.1.2, 6.1.3, 7.3.4" -InformationAction Continue Write-Information "Full audit results exported however, none of the following tests had exports: `n1.1.1, 1.3.1, 6.1.2, 6.1.3, 7.3.4"
} }
else { else {
Write-Information "No specified tests were included in the export." -InformationAction Continue Write-Information "No specified tests were included in the export."
} }
} }
if ($ExportOriginalTests) { if ($ExportOriginalTests) {
@@ -200,7 +178,7 @@ function Export-M365SecurityAuditTable {
$TestNumbersToCheck = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4" $TestNumbersToCheck = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4"
# Check for large details and update the AuditResults array # Check for large details and update the AuditResults array
$updatedAuditResults = Get-ExceededLengthResultDetail -AuditResults $AuditResults -TestNumbersToCheck $TestNumbersToCheck -ExportedTests $exportedTests -DetailsLengthLimit 30000 -PreviewLineCount 25 $updatedAuditResults = Get-ExceededLengthResultDetail -AuditResults $AuditResults -TestNumbersToCheck $TestNumbersToCheck -ExportedTests $exportedTests -DetailsLengthLimit 30000 -PreviewLineCount 25
$originalFileName = "$ExportPath\$timestamp`_M365FoundationsAudit.csv" $originalFileName = "$ExportPath\$timestamp`_$Prefix-M365FoundationsAudit.csv"
if ($ExportToExcel) { if ($ExportToExcel) {
$xlsxPath = [System.IO.Path]::ChangeExtension($originalFileName, '.xlsx') $xlsxPath = [System.IO.Path]::ChangeExtension($originalFileName, '.xlsx')
$updatedAuditResults | Export-Excel -Path $xlsxPath -WorksheetName Table -TableName Table -AutoSize -TableStyle Medium2 $updatedAuditResults | Export-Excel -Path $xlsxPath -WorksheetName Table -TableName Table -AutoSize -TableStyle Medium2
@@ -221,32 +199,29 @@ function Export-M365SecurityAuditTable {
} }
$fileHashes | Set-Content -Path $hashFilePath $fileHashes | Set-Content -Path $hashFilePath
$createdFiles += $hashFilePath # Add the hash file to the array $createdFiles += $hashFilePath # Add the hash file to the array
# Create a zip file and add all the created files # Create a zip file and add all the created files
$zipFilePath = "$ExportPath\$timestamp`_M365FoundationsAudit.zip" $zipFilePath = "$ExportPath\$timestamp`_$Prefix-M365FoundationsAudit.zip"
Compress-Archive -Path $createdFiles -DestinationPath $zipFilePath Compress-Archive -Path $createdFiles -DestinationPath $zipFilePath
# Remove the original files after they have been added to the zip # Remove the original files after they have been added to the zip
foreach ($file in $createdFiles) { foreach ($file in $createdFiles) {
Remove-Item -Path $file -Force Remove-Item -Path $file -Force
} }
# Compute the hash for the zip file and rename it # Compute the hash for the zip file and rename it
$zipHash = Get-FileHash -Path $zipFilePath -Algorithm SHA256 $zipHash = Get-FileHash -Path $zipFilePath -Algorithm SHA256
$newZipFilePath = "$ExportPath\$timestamp`_M365FoundationsAudit_$($zipHash.Hash.Substring(0, 8)).zip" $newZipFilePath = "$ExportPath\$timestamp`_$Prefix-M365FoundationsAudit_$($zipHash.Hash.Substring(0, 8)).zip"
Rename-Item -Path $zipFilePath -NewName $newZipFilePath Rename-Item -Path $zipFilePath -NewName $newZipFilePath
# Output the zip file path with hash # Output the zip file path with hash
[PSCustomObject]@{ return [PSCustomObject]@{
ZipFilePath = $newZipFilePath ZipFilePath = $newZipFilePath
} }
}
} # End of ExportPath } # End of ExportPath
elseif ($OutputTestNumber) { elseif ($OutputTestNumber) {
if ($results[0].Details) { if ($results[0].Details) {
return $results[0].Details return $results[0].Details
} }
else { else {
Write-Information "No results found for test number $($OutputTestNumber)." -InformationAction Continue Write-Information "No results found for test number $($OutputTestNumber)."
} }
} }
else { else {

View File

@@ -2,15 +2,17 @@
.SYNOPSIS .SYNOPSIS
Invokes a security audit for Microsoft 365 environments. Invokes a security audit for Microsoft 365 environments.
.DESCRIPTION .DESCRIPTION
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, such as compliance with CIS benchmarks. 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".
.PARAMETER TenantAdminUrl .PARAMETER TenantAdminUrl
The URL of the tenant admin. If not specified, none of the SharePoint Online tests will run. The URL of the tenant admin. If not specified, none of the SharePoint Online tests will run.
.PARAMETER DomainName .PARAMETER 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. 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
.PARAMETER ELevel .PARAMETER ELevel
Specifies the E-Level (E3 or E5) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter. Specifies the E-Level (E3 or E5) for the audit. This parameter is optional and can be combined with the ProfileLevel parameter.
.PARAMETER ProfileLevel .PARAMETER ProfileLevel
Specifies the profile level (L1 or L2) for the audit. This parameter is optional and can be combined with the ELevel parameter. 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.
.PARAMETER IncludeIG1 .PARAMETER IncludeIG1
If specified, includes tests where IG1 is true. If specified, includes tests where IG1 is true.
.PARAMETER IncludeIG2 .PARAMETER IncludeIG2
@@ -22,9 +24,11 @@
.PARAMETER SkipRecommendation .PARAMETER SkipRecommendation
Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers. Specifies specific recommendations to exclude from the audit. Accepts an array of recommendation numbers.
.PARAMETER ApprovedCloudStorageProviders .PARAMETER ApprovedCloudStorageProviders
Specifies the approved cloud storage providers for the audit. Accepts an array of cloud storage provider names. 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'
.PARAMETER ApprovedFederatedDomains .PARAMETER ApprovedFederatedDomains
Specifies the approved federated domains for the audit test 8.2.1. Accepts an array of allowed domain names. 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.
.PARAMETER DoNotConnect .PARAMETER DoNotConnect
If specified, the cmdlet will not establish a connection to Microsoft 365 services. If specified, the cmdlet will not establish a connection to Microsoft 365 services.
.PARAMETER DoNotDisconnect .PARAMETER DoNotDisconnect
@@ -33,80 +37,40 @@
If specified, the cmdlet will not check for the presence of required modules. If specified, the cmdlet will not check for the presence of required modules.
.PARAMETER DoNotConfirmConnections .PARAMETER DoNotConfirmConnections
If specified, the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them. If specified, the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them.
.PARAMETER AuthParams
Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.
.EXAMPLE .EXAMPLE
PS> Invoke-M365SecurityAudit PS> Invoke-M365SecurityAudit
# Performs a security audit using default parameters.
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 .EXAMPLE
PS> Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ELevel "E5" -ProfileLevel "L1" PS> 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.
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 .EXAMPLE
PS> Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -IncludeIG1 PS> Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -IncludeIG1
# Performs a security audit while including tests where IG1 is true.
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 .EXAMPLE
PS> Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -SkipRecommendation '1.1.3', '2.1.1' PS> 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. # 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 .EXAMPLE
PS> $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" PS> $auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com"
PS> Export-M365SecurityAuditTable -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests -ExportAllTests
.EXAMPLE
# (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 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).
Captures the audit results into a variable and exports them to a CSV file.
Output: Output:
CISAuditResult[] CISAuditResult[]
auditResults.csv auditResults.csv
.EXAMPLE .EXAMPLE
PS> Invoke-M365SecurityAudit -WhatIf PS> Invoke-M365SecurityAudit -WhatIf
Displays what would happen if the cmdlet is run without actually performing the audit. Displays what would happen if the cmdlet is run without actually performing the audit.
Output: Output:
What if: Performing the operation "Invoke-M365SecurityAudit" on target "Microsoft 365 environment". What if: Performing the operation "Invoke-M365SecurityAudit" on target "Microsoft 365 environment".
@@ -126,7 +90,8 @@
https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Invoke-M365SecurityAudit https://criticalsolutionsnetwork.github.io/M365FoundationsCISReport/#Invoke-M365SecurityAudit
#> #>
function Invoke-M365SecurityAudit { function Invoke-M365SecurityAudit {
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'Default')] # Add confirm to high
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High" , DefaultParameterSetName = 'Default')]
[OutputType([CISAuditResult[]])] [OutputType([CISAuditResult[]])]
param ( param (
[Parameter(Mandatory = $false, HelpMessage = "The SharePoint tenant admin URL, which should end with '-admin.sharepoint.com'. If not specified none of the Sharepoint Online tests will run.")] [Parameter(Mandatory = $false, HelpMessage = "The SharePoint tenant admin URL, which should end with '-admin.sharepoint.com'. If not specified none of the Sharepoint Online tests will run.")]
@@ -189,19 +154,25 @@ function Invoke-M365SecurityAudit {
[Parameter(Mandatory = $false, HelpMessage = "Specifies that the cmdlet will not check for the presence of required modules.")] [Parameter(Mandatory = $false, HelpMessage = "Specifies that the cmdlet will not check for the presence of required modules.")]
[switch]$NoModuleCheck, [switch]$NoModuleCheck,
[Parameter(Mandatory = $false, HelpMessage = "Specifies that the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them.")] [Parameter(Mandatory = $false, HelpMessage = "Specifies that the cmdlet will not prompt for confirmation before proceeding with established connections and will disconnect from all of them.")]
[switch]$DoNotConfirmConnections [switch]$DoNotConfirmConnections,
[Parameter(Mandatory = $false, HelpMessage = "Specifies an authentication object containing parameters for application-based authentication.")]
[CISAuthenticationParameters]$AuthParams
) )
Begin { Begin {
if ($script:MaximumFunctionCount -lt 8192) { if ($script:MaximumFunctionCount -lt 8192) {
Write-Verbose "Setting the `$script:MaximumFunctionCount to 8192 for the test run."
$script:MaximumFunctionCount = 8192 $script:MaximumFunctionCount = 8192
} }
if ($AuthParams) {
$script:PnpAuth = $true
}
# Ensure required modules are installed # Ensure required modules are installed
$requiredModules = Get-RequiredModule -AuditFunction $requiredModules = Get-RequiredModule -AuditFunction
# Format the required modules list # Format the required modules list
$requiredModulesFormatted = Format-RequiredModuleList -RequiredModules $requiredModules $requiredModulesFormatted = Format-RequiredModuleList -RequiredModules $requiredModules
# Check and install required modules if necessary # Check and install required modules if necessary
if (!($NoModuleCheck) -and $PSCmdlet.ShouldProcess("Check for required modules: $requiredModulesFormatted", "Check")) { if (!($NoModuleCheck) -and $PSCmdlet.ShouldProcess("Modules: $requiredModulesFormatted", "Assert-ModuleAvailability")) {
Write-Host "Checking for and installing required modules..." -ForegroundColor DarkMagenta Write-Information "Checking for and installing required modules..."
foreach ($module in $requiredModules) { foreach ($module in $requiredModules) {
Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModules $module.SubModules Assert-ModuleAvailability -ModuleName $module.ModuleName -RequiredVersion $module.RequiredVersion -SubModules $module.SubModules
} }
@@ -251,16 +222,16 @@ function Invoke-M365SecurityAudit {
try { try {
$actualUniqueConnections = Get-UniqueConnection -Connections $requiredConnections $actualUniqueConnections = Get-UniqueConnection -Connections $requiredConnections
if (!($DoNotConnect) -and $PSCmdlet.ShouldProcess("Establish connections to Microsoft 365 services: $($actualUniqueConnections -join ', ')", "Connect")) { if (!($DoNotConnect) -and $PSCmdlet.ShouldProcess("Establish connections to Microsoft 365 services: $($actualUniqueConnections -join ', ')", "Connect")) {
Write-Host "Establishing connections to Microsoft 365 services: $($actualUniqueConnections -join ', ')" -ForegroundColor DarkMagenta Write-Information "Establishing connections to Microsoft 365 services: $($actualUniqueConnections -join ', ')"
Connect-M365Suite -TenantAdminUrl $TenantAdminUrl -RequiredConnections $requiredConnections -SkipConfirmation:$DoNotConfirmConnections Connect-M365Suite -TenantAdminUrl $TenantAdminUrl -RequiredConnections $requiredConnections -SkipConfirmation:$DoNotConfirmConnections -AuthParams $AuthParams
} }
} }
catch { catch {
Write-Host "Connection execution aborted: $_" -ForegroundColor Red Throw "Connection execution aborted: $_"
break
} }
try { try {
Write-Host "A total of $($totalTests) tests were selected to run..." -ForegroundColor DarkMagenta if ($PSCmdlet.ShouldProcess("Measure and display audit results for $($totalTests) tests", "Measure")) {
Write-Information "A total of $($totalTests) tests were selected to run..."
# Import the test functions # Import the test functions
$testFiles | ForEach-Object { $testFiles | ForEach-Object {
$currentTestIndex++ $currentTestIndex++
@@ -271,7 +242,7 @@ function Invoke-M365SecurityAudit {
} }
Catch { Catch {
# Log the error and add the test to the failed tests collection # Log the error and add the test to the failed tests collection
Write-Verbose "Failed to load test function $($_.Name): $_" -Verbose Write-Verbose "Failed to load test function $($_.Name): $_"
$script:FailedTests.Add([PSCustomObject]@{ Test = $_.Name; Error = $_ }) $script:FailedTests.Add([PSCustomObject]@{ Test = $_.Name; Error = $_ })
} }
} }
@@ -281,16 +252,29 @@ function Invoke-M365SecurityAudit {
$currentTestIndex++ $currentTestIndex++
Write-Progress -Activity "Executing Tests" -Status "Executing $($currentTestIndex) of $($totalTests): $($testFunction.Name)" -PercentComplete (($currentTestIndex / $totalTests) * 100) Write-Progress -Activity "Executing Tests" -Status "Executing $($currentTestIndex) of $($totalTests): $($testFunction.Name)" -PercentComplete (($currentTestIndex / $totalTests) * 100)
$functionName = $testFunction.BaseName $functionName = $testFunction.BaseName
if ($PSCmdlet.ShouldProcess($functionName, "Execute test")) { Write-Information "Executing test function: $functionName"
$auditResult = Invoke-TestFunction -FunctionFile $testFunction -DomainName $DomainName -ApprovedCloudStorageProviders $ApprovedCloudStorageProviders -ApprovedFederatedDomains $ApprovedFederatedDomains $auditResult = Invoke-TestFunction -FunctionFile $testFunction -DomainName $DomainName -ApprovedCloudStorageProviders $ApprovedCloudStorageProviders -ApprovedFederatedDomains $ApprovedFederatedDomains
# Add the result to the collection # Add the result to the collection
[void]$allAuditResults.Add($auditResult) [void]$allAuditResults.Add($auditResult)
} }
# Call the private function to calculate and display results
Measure-AuditResult -AllAuditResults $allAuditResults -FailedTests $script:FailedTests
# Return all collected audit results
# Define the test numbers to check
$TestNumbersToCheck = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4"
# Check for large details in the audit results
$exceedingTests = Get-ExceededLengthResultDetail -AuditResults $allAuditResults -TestNumbersToCheck $TestNumbersToCheck -ReturnExceedingTestsOnly -DetailsLengthLimit 30000
if ($exceedingTests.Count -gt 0) {
Write-Information "The following tests exceeded the details length limit: $($exceedingTests -join ', ')"
Write-Information "( Assuming the results were instantiated. Ex: `$object = invoke-M365SecurityAudit )`nUse the following command and adjust as necessary to view the full details of the test results:"
Write-Information "Export-M365SecurityAuditTable -ExportAllTests -AuditResults `$object -ExportPath `"C:\temp`" -ExportOriginalTests"
}
return $allAuditResults.ToArray() | Sort-Object -Property Rec
} }
} }
catch { catch {
# Log the error and add the test to the failed tests collection # Log the error and add the test to the failed tests collection
Write-Verbose "Invoke-M365SecurityAudit: Failed to load test function $($_.Name): $_" -Verbose throw "Failed to execute test function $($testFunction.Name): $_"
$script:FailedTests.Add([PSCustomObject]@{ Test = $_.Name; Error = $_ }) $script:FailedTests.Add([PSCustomObject]@{ Test = $_.Name; Error = $_ })
} }
finally { finally {
@@ -301,20 +285,6 @@ function Invoke-M365SecurityAudit {
} }
} }
End { End {
if ($PSCmdlet.ShouldProcess("Measure and display audit results for $($totalTests) tests", "Measure")) {
# Call the private function to calculate and display results
Measure-AuditResult -AllAuditResults $allAuditResults -FailedTests $script:FailedTests
# Return all collected audit results
# Define the test numbers to check
$TestNumbersToCheck = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4"
# Check for large details in the audit results
$exceedingTests = Get-ExceededLengthResultDetail -AuditResults $allAuditResults -TestNumbersToCheck $TestNumbersToCheck -ReturnExceedingTestsOnly -DetailsLengthLimit 30000
if ($exceedingTests.Count -gt 0) {
Write-Information "The following tests exceeded the details length limit: $($exceedingTests -join ', ')" -InformationAction Continue
Write-Host "(Assuming the results were instantiated. Ex: `$object = invoke-M365SecurityAudit) Use the following command and adjust as neccesary to view the full details of the test results:" -ForegroundColor DarkCyan
Write-Host "Export-M365SecurityAuditTable -ExportAllTests -AuditResults `$object -ExportPath `"C:\temp`" -ExportOriginalTests" -ForegroundColor Green
}
return $allAuditResults.ToArray() | Sort-Object -Property Rec
}
} }
} }

View File

@@ -0,0 +1,64 @@
<#
.SYNOPSIS
Creates a new CISAuthenticationParameters object for Microsoft 365 authentication.
.DESCRIPTION
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.
.PARAMETER ClientCertThumbPrint
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.
.PARAMETER ClientId
The Client ID (Application ID) of the Azure AD application. It must be a valid GUID format.
.PARAMETER TenantId
The Tenant ID of the Azure AD directory. It must be a valid GUID format representing your Microsoft 365 tenant.
.PARAMETER OnMicrosoftUrl
The URL of your onmicrosoft.com domain. It should be in the format 'example.onmicrosoft.com'.
.PARAMETER SpAdminUrl
The SharePoint admin URL, which should end with '-admin.sharepoint.com'. This URL is used for connecting to SharePoint Online.
.INPUTS
None. You cannot pipe objects to this function.
.OUTPUTS
CISAuthenticationParameters
The function returns an instance of the CISAuthenticationParameters class containing the authentication details.
.EXAMPLE
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"
Creates a new CISAuthenticationParameters object with the specified credentials and URLs, validating each parameter's format and length.
.NOTES
Requires PowerShell 7.0 or later.
#>
function New-M365SecurityAuditAuthObject {
[CmdletBinding()]
[OutputType([CISAuthenticationParameters])]
param(
[Parameter(Mandatory = $true, HelpMessage = "The 40-character hexadecimal thumbprint of the client certificate.")]
[ValidatePattern("^[0-9a-fA-F]{40}$")] # Regex for a valid thumbprint format
[ValidateLength(40, 40)] # Enforce exact length
[string]$ClientCertThumbPrint,
[Parameter(Mandatory = $true, HelpMessage = "The Client ID (GUID format) of the Azure AD application.")]
[ValidatePattern("^[0-9a-fA-F\-]{36}$")] # Regex for a valid GUID
[string]$ClientId,
[Parameter(Mandatory = $true, HelpMessage = "The Tenant ID (GUID format) of the Azure AD directory.")]
[ValidatePattern("^[0-9a-fA-F\-]{36}$")] # Regex for a valid GUID
[string]$TenantId,
[Parameter(Mandatory = $true, HelpMessage = "The onmicrosoft.com domain URL (e.g., 'example.onmicrosoft.com').")]
[ValidatePattern("^[a-zA-Z0-9]+\.onmicrosoft\.com$")] # Regex for a valid onmicrosoft.com URL
[string]$OnMicrosoftUrl,
[Parameter(Mandatory = $true, HelpMessage = "The SharePoint admin URL ending with '-admin.sharepoint.com'.")]
[ValidatePattern("^https:\/\/[a-zA-Z0-9\-]+\-admin\.sharepoint\.com$")] # Regex for a valid SharePoint admin URL
[string]$SpAdminUrl
)
# Create and return the authentication parameters object
return [CISAuthenticationParameters]::new(
$ClientCertThumbPrint,
$ClientId,
$TenantId,
$OnMicrosoftUrl,
$SpAdminUrl
)
}

View File

@@ -22,28 +22,21 @@ function Remove-RowsWithEmptyCSVStatus {
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$WorksheetName [string]$WorksheetName
) )
# Import the Excel file # Import the Excel file
$ExcelData = Import-Excel -Path $FilePath -WorksheetName $WorksheetName $ExcelData = Import-Excel -Path $FilePath -WorksheetName $WorksheetName
# Check if CSV_Status column exists # Check if CSV_Status column exists
if (-not $ExcelData.PSObject.Properties.Match("CSV_Status")) { if (-not $ExcelData.PSObject.Properties.Match("CSV_Status")) {
throw "CSV_Status column not found in the worksheet." throw "CSV_Status column not found in the worksheet."
} }
# Filter rows where CSV_Status is not empty # Filter rows where CSV_Status is not empty
$FilteredData = $ExcelData | Where-Object { $null -ne $_.CSV_Status -and $_.CSV_Status -ne '' } $FilteredData = $ExcelData | Where-Object { $null -ne $_.CSV_Status -and $_.CSV_Status -ne '' }
# Get the original file name and directory # Get the original file name and directory
$OriginalFileName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath) $OriginalFileName = [System.IO.Path]::GetFileNameWithoutExtension($FilePath)
$Directory = [System.IO.Path]::GetDirectoryName($FilePath) $Directory = [System.IO.Path]::GetDirectoryName($FilePath)
# Create a new file name for the filtered data # Create a new file name for the filtered data
$NewFileName = "$OriginalFileName-Filtered.xlsx" $NewFileName = "$OriginalFileName-Filtered.xlsx"
$NewFilePath = Join-Path -Path $Directory -ChildPath $NewFileName $NewFilePath = Join-Path -Path $Directory -ChildPath $NewFileName
# Export the filtered data to a new Excel file # Export the filtered data to a new Excel file
$FilteredData | Export-Excel -Path $NewFilePath -WorksheetName $WorksheetName -Show $FilteredData | Export-Excel -Path $NewFilePath -WorksheetName $WorksheetName -Show
Write-Output "Filtered Excel file created at $NewFilePath" Write-Output "Filtered Excel file created at $NewFilePath"
} }

View File

@@ -39,13 +39,47 @@
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name>
<maml:description>
<maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:description>
<maml:para>Prompts you for confirmation before running the cmdlet.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Export-M365SecurityAuditTable</maml:name> <maml:name>Export-M365SecurityAuditTable</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none">
<maml:name>ExportAllTests</maml:name> <maml:name>ExportNestedTables</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export all test results.</maml:para> <maml:para>Switch to export all test results. When specified, all test results are exported to the specified path.</maml:para>
</maml:description> </maml:description>
<dev:type> <dev:type>
<maml:name>SwitchParameter</maml:name> <maml:name>SwitchParameter</maml:name>
@@ -77,7 +111,7 @@
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>ExportOriginalTests</maml:name> <maml:name>ExportOriginalTests</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export the original audit results to a CSV file.</maml:para> <maml:para>Switch to export the original audit results to a CSV file.</maml:para>
@@ -99,6 +133,52 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Prefix</maml:name>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>Corp</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name>
<maml:description>
<maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:description>
<maml:para>Prompts you for confirmation before running the cmdlet.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Export-M365SecurityAuditTable</maml:name> <maml:name>Export-M365SecurityAuditTable</maml:name>
@@ -126,13 +206,47 @@
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name>
<maml:description>
<maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:description>
<maml:para>Prompts you for confirmation before running the cmdlet.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Export-M365SecurityAuditTable</maml:name> <maml:name>Export-M365SecurityAuditTable</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none">
<maml:name>ExportAllTests</maml:name> <maml:name>ExportNestedTables</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export all test results.</maml:para> <maml:para>Switch to export all test results. When specified, all test results are exported to the specified path.</maml:para>
</maml:description> </maml:description>
<dev:type> <dev:type>
<maml:name>SwitchParameter</maml:name> <maml:name>SwitchParameter</maml:name>
@@ -164,7 +278,7 @@
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>ExportOriginalTests</maml:name> <maml:name>ExportOriginalTests</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export the original audit results to a CSV file.</maml:para> <maml:para>Switch to export the original audit results to a CSV file.</maml:para>
@@ -186,6 +300,52 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Prefix</maml:name>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>Corp</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name>
<maml:description>
<maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:description>
<maml:para>Prompts you for confirmation before running the cmdlet.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -226,9 +386,9 @@
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none">
<maml:name>ExportAllTests</maml:name> <maml:name>ExportNestedTables</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export all test results.</maml:para> <maml:para>Switch to export all test results. When specified, all test results are exported to the specified path.</maml:para>
</maml:description> </maml:description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type> <dev:type>
@@ -249,7 +409,7 @@
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>ExportOriginalTests</maml:name> <maml:name>ExportOriginalTests</maml:name>
<maml:description> <maml:description>
<maml:para>Switch to export the original audit results to a CSV file.</maml:para> <maml:para>Switch to export the original audit results to a CSV file.</maml:para>
@@ -273,6 +433,54 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Prefix</maml:name>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>Corp</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name>
<maml:description>
<maml:para>Shows what would happen if the cmdlet runs. The cmdlet is not run.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="cf">
<maml:name>Confirm</maml:name>
<maml:description>
<maml:para>Prompts you for confirmation before running the cmdlet.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes> <command:inputTypes>
<command:inputType> <command:inputType>
@@ -390,6 +598,18 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -405,6 +625,18 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes> <command:inputTypes>
<command:inputType> <command:inputType>
@@ -500,6 +732,18 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -527,6 +771,18 @@
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes /> <command:inputTypes />
<command:returnValues> <command:returnValues>
@@ -726,6 +982,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -813,6 +1081,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes /> <command:inputTypes />
<command:returnValues> <command:returnValues>
@@ -984,6 +1264,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1006,6 +1298,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Invoke-M365SecurityAudit</maml:name> <maml:name>Invoke-M365SecurityAudit</maml:name>
@@ -1112,6 +1416,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1134,6 +1450,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Invoke-M365SecurityAudit</maml:name> <maml:name>Invoke-M365SecurityAudit</maml:name>
@@ -1240,6 +1568,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1262,6 +1602,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Invoke-M365SecurityAudit</maml:name> <maml:name>Invoke-M365SecurityAudit</maml:name>
@@ -1368,6 +1720,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1390,6 +1754,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Invoke-M365SecurityAudit</maml:name> <maml:name>Invoke-M365SecurityAudit</maml:name>
@@ -1497,6 +1873,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1519,6 +1907,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
<command:syntaxItem> <command:syntaxItem>
<maml:name>Invoke-M365SecurityAudit</maml:name> <maml:name>Invoke-M365SecurityAudit</maml:name>
@@ -1626,6 +2026,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1648,6 +2060,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -1831,6 +2255,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>AuthParams</maml:name>
<maml:description>
<maml:para>Specifies an authentication object containing parameters for application-based authentication. If provided, this will be used for connecting to services.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">CISAuthenticationParameters</command:parameterValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi"> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="wi">
<maml:name>WhatIf</maml:name> <maml:name>WhatIf</maml:name>
<maml:description> <maml:description>
@@ -1855,6 +2291,18 @@ Retrieves the MFA status for the specified user with the UPN "example@domain.com
</dev:type> </dev:type>
<dev:defaultValue>False</dev:defaultValue> <dev:defaultValue>False</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes> <command:inputTypes>
<command:inputType> <command:inputType>
@@ -1959,6 +2407,218 @@ PS&gt; $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation</d
</maml:navigationLink> </maml:navigationLink>
</command:relatedLinks> </command:relatedLinks>
</command:command> </command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<command:details>
<command:name>New-M365SecurityAuditAuthObject</command:name>
<command:verb>New</command:verb>
<command:noun>M365SecurityAuditAuthObject</command:noun>
<maml:description>
<maml:para>Creates a new CISAuthenticationParameters object for Microsoft 365 authentication.</maml:para>
</maml:description>
</command:details>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>New-M365SecurityAuditAuthObject</maml:name>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none">
<maml:name>ClientCertThumbPrint</maml:name>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="2" aliases="none">
<maml:name>ClientId</maml:name>
<maml:description>
<maml:para>The Client ID (Application ID) of the Azure AD application. It must be a valid GUID format.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="3" aliases="none">
<maml:name>TenantId</maml:name>
<maml:description>
<maml:para>The Tenant ID of the Azure AD directory. It must be a valid GUID format representing your Microsoft 365 tenant.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="4" aliases="none">
<maml:name>OnMicrosoftUrl</maml:name>
<maml:description>
<maml:para>The URL of your onmicrosoft.com domain. It should be in the format 'example.onmicrosoft.com'.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="5" aliases="none">
<maml:name>SpAdminUrl</maml:name>
<maml:description>
<maml:para>The SharePoint admin URL, which should end with '-admin.sharepoint.com'. This URL is used for connecting to SharePoint Online.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
</command:syntax>
<command:parameters>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="1" aliases="none">
<maml:name>ClientCertThumbPrint</maml:name>
<maml:description>
<maml:para>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.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="2" aliases="none">
<maml:name>ClientId</maml:name>
<maml:description>
<maml:para>The Client ID (Application ID) of the Azure AD application. It must be a valid GUID format.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="3" aliases="none">
<maml:name>TenantId</maml:name>
<maml:description>
<maml:para>The Tenant ID of the Azure AD directory. It must be a valid GUID format representing your Microsoft 365 tenant.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="4" aliases="none">
<maml:name>OnMicrosoftUrl</maml:name>
<maml:description>
<maml:para>The URL of your onmicrosoft.com domain. It should be in the format 'example.onmicrosoft.com'.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="true" variableLength="true" globbing="false" pipelineInput="False" position="5" aliases="none">
<maml:name>SpAdminUrl</maml:name>
<maml:description>
<maml:para>The SharePoint admin URL, which should end with '-admin.sharepoint.com'. This URL is used for connecting to SharePoint Online.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:inputTypes>
<command:inputType>
<dev:type>
<maml:name>None. You cannot pipe objects to this function.</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:inputType>
</command:inputTypes>
<command:returnValues>
<command:returnValue>
<dev:type>
<maml:name>CISAuthenticationParameters</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
<command:returnValue>
<dev:type>
<maml:name>The function returns an instance of the CISAuthenticationParameters class containing the authentication details.</maml:name>
</dev:type>
<maml:description>
<maml:para></maml:para>
</maml:description>
</command:returnValue>
</command:returnValues>
<maml:alertSet>
<maml:alert>
<maml:para>Requires PowerShell 7.0 or later.</maml:para>
</maml:alert>
</maml:alertSet>
<command:examples>
<command:example>
<maml:title>-------------------------- EXAMPLE 1 --------------------------</maml:title>
<dev:code>$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.</dev:code>
<dev:remarks>
<maml:para></maml:para>
</dev:remarks>
</command:example>
</command:examples>
<command:relatedLinks />
</command:command>
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp"> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<command:details> <command:details>
<command:name>Remove-RowsWithEmptyCSVStatus</command:name> <command:name>Remove-RowsWithEmptyCSVStatus</command:name>
@@ -1998,6 +2658,18 @@ PS&gt; $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation</d
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -2025,6 +2697,18 @@ PS&gt; $auditResults | Export-Csv -Path "auditResults.csv" -NoTypeInformation</d
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes /> <command:inputTypes />
<command:returnValues /> <command:returnValues />
@@ -2096,6 +2780,18 @@ This command imports data from the "Sheet1" worksheet in the "Report.xlsx" file,
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem> </command:syntaxItem>
</command:syntax> </command:syntax>
<command:parameters> <command:parameters>
@@ -2135,6 +2831,18 @@ This command imports data from the "Sheet1" worksheet in the "Report.xlsx" file,
</dev:type> </dev:type>
<dev:defaultValue>None</dev:defaultValue> <dev:defaultValue>None</dev:defaultValue>
</command:parameter> </command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>{{ Fill ProgressAction Description }}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters> </command:parameters>
<command:inputTypes> <command:inputTypes>
<command:inputType> <command:inputType>

View File

@@ -30,9 +30,11 @@ Optional Subtopics
EXAMPLES EXAMPLES
# Example 1: Performing a security audit based on CIS benchmarks # 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"
$auditResults = Invoke-M365SecurityAudit -TenantAdminUrl "https://contoso-admin.sharepoint.com" -DomainName "contoso.com" -ApprovedCloudStorageProviders "DropBox" -ApprovedFederatedDomains "northwind.com"
# Example 2: Exporting a security audit table to a CSV file # Example 2: Exporting a security audit and it's nested tables to zipped CSV files
Export-M365SecurityAuditTable -ExportAllTests -AuditResults $auditResults -ExportPath "C:\temp" -ExportOriginalTests 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 # Example 3: Retrieving licenses for users in administrative roles
Get-AdminRoleUserLicense Get-AdminRoleUserLicense
@@ -49,6 +51,14 @@ EXAMPLES
# Example 7: Granting Microsoft Graph permissions to the auditor # Example 7: Granting Microsoft Graph permissions to the auditor
Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent 'user@example.com' Grant-M365SecurityAuditConsent -UserPrincipalNameForConsent 'user@example.com'
# Example 8: (PowerShell 7.x Only) Creating a new authentication object for the security audit for app-based authentication.
$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"
NOTE NOTE
Ensure that you have the necessary permissions and administrative roles in Ensure that you have the necessary permissions and administrative roles in
your Microsoft 365 environment to run these cmdlets. Proper configuration your Microsoft 365 environment to run these cmdlets. Proper configuration

View File

@@ -2,7 +2,7 @@
1,Test-AdministrativeAccountCompliance.ps1,1.1.1,Ensure Administrative accounts are separate and cloud-only,E3,L1,5.4,Restrict Administrator Privileges to Dedicated Administrator Accounts,TRUE,TRUE,TRUE,FALSE,Microsoft Graph 1,Test-AdministrativeAccountCompliance.ps1,1.1.1,Ensure Administrative accounts are separate and cloud-only,E3,L1,5.4,Restrict Administrator Privileges to Dedicated Administrator Accounts,TRUE,TRUE,TRUE,FALSE,Microsoft Graph
2,Test-GlobalAdminsCount.ps1,1.1.3,Ensure that between two and four global admins are designated,E3,L1,5.1,Establish and Maintain an Inventory of Accounts,TRUE,TRUE,TRUE,TRUE,Microsoft Graph 2,Test-GlobalAdminsCount.ps1,1.1.3,Ensure that between two and four global admins are designated,E3,L1,5.1,Establish and Maintain an Inventory of Accounts,TRUE,TRUE,TRUE,TRUE,Microsoft Graph
3,Test-ManagedApprovedPublicGroups.ps1,1.2.1,Ensure that only organizationally managed/approved public groups exist,E3,L2,3.3,Configure Data Access Control Lists,TRUE,TRUE,TRUE,TRUE,Microsoft Graph 3,Test-ManagedApprovedPublicGroups.ps1,1.2.1,Ensure that only organizationally managed/approved public groups exist,E3,L2,3.3,Configure Data Access Control Lists,TRUE,TRUE,TRUE,TRUE,Microsoft Graph
4,Test-BlockSharedMailboxSignIn.ps1,1.2.2,Ensure sign-in to shared mailboxes is blocked,E3,L1,0,Explicitly Not Mapped,FALSE,FALSE,FALSE,TRUE,AzureAD | EXO 4,Test-BlockSharedMailboxSignIn.ps1,1.2.2,Ensure sign-in to shared mailboxes is blocked,E3,L1,0,Explicitly Not Mapped,FALSE,FALSE,FALSE,TRUE,EXO | Microsoft Graph
5,Test-PasswordNeverExpirePolicy.ps1,1.3.1,Ensure the 'Password expiration policy' is set to 'Set passwords to never expire',E3,L1,5.2,Use Unique Passwords,TRUE,TRUE,TRUE,TRUE,Microsoft Graph 5,Test-PasswordNeverExpirePolicy.ps1,1.3.1,Ensure the 'Password expiration policy' is set to 'Set passwords to never expire',E3,L1,5.2,Use Unique Passwords,TRUE,TRUE,TRUE,TRUE,Microsoft Graph
6,Test-ExternalSharingCalendars.ps1,1.3.3,Ensure 'External sharing' of calendars is not available,E3,L2,4.8,Uninstall or Disable Unnecessary Services on Enterprise Assets and Software,FALSE,TRUE,TRUE,TRUE,EXO 6,Test-ExternalSharingCalendars.ps1,1.3.3,Ensure 'External sharing' of calendars is not available,E3,L2,4.8,Uninstall or Disable Unnecessary Services on Enterprise Assets and Software,FALSE,TRUE,TRUE,TRUE,EXO
7,Test-CustomerLockbox.ps1,1.3.6,Ensure the customer lockbox feature is enabled,E5,L2,0,Explicitly Not Mapped,FALSE,FALSE,FALSE,TRUE,EXO 7,Test-CustomerLockbox.ps1,1.3.6,Ensure the customer lockbox feature is enabled,E5,L2,0,Explicitly Not Mapped,FALSE,FALSE,FALSE,TRUE,EXO
1 Index TestFileName Rec RecDescription ELevel ProfileLevel CISControl CISDescription IG1 IG2 IG3 Automated Connection
2 1 Test-AdministrativeAccountCompliance.ps1 1.1.1 Ensure Administrative accounts are separate and cloud-only E3 L1 5.4 Restrict Administrator Privileges to Dedicated Administrator Accounts TRUE TRUE TRUE FALSE Microsoft Graph
3 2 Test-GlobalAdminsCount.ps1 1.1.3 Ensure that between two and four global admins are designated E3 L1 5.1 Establish and Maintain an Inventory of Accounts TRUE TRUE TRUE TRUE Microsoft Graph
4 3 Test-ManagedApprovedPublicGroups.ps1 1.2.1 Ensure that only organizationally managed/approved public groups exist E3 L2 3.3 Configure Data Access Control Lists TRUE TRUE TRUE TRUE Microsoft Graph
5 4 Test-BlockSharedMailboxSignIn.ps1 1.2.2 Ensure sign-in to shared mailboxes is blocked E3 L1 0 Explicitly Not Mapped FALSE FALSE FALSE TRUE AzureAD | EXO EXO | Microsoft Graph
6 5 Test-PasswordNeverExpirePolicy.ps1 1.3.1 Ensure the 'Password expiration policy' is set to 'Set passwords to never expire' E3 L1 5.2 Use Unique Passwords TRUE TRUE TRUE TRUE Microsoft Graph
7 6 Test-ExternalSharingCalendars.ps1 1.3.3 Ensure 'External sharing' of calendars is not available E3 L2 4.8 Uninstall or Disable Unnecessary Services on Enterprise Assets and Software FALSE TRUE TRUE TRUE EXO
8 7 Test-CustomerLockbox.ps1 1.3.6 Ensure the customer lockbox feature is enabled E5 L2 0 Explicitly Not Mapped FALSE FALSE FALSE TRUE EXO

View File

@@ -215,7 +215,7 @@ function Test-AntiPhishingPolicy {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
$auditResult = Get-TestError -LastError $_ -recnum $recnum $auditResult = Get-TestError -LastError $_ -recnum $recnum
} }
} }

View File

@@ -58,9 +58,9 @@ function Test-BlockSharedMailboxSignIn {
} }
) )
#> #>
$users = Get-CISAadOutput -Rec $recnum $users = Get-CISMgOutput -Rec $recnum
# Step: Retrieve details of shared mailboxes from Azure AD (Condition B: Pass/Fail) # Step: Retrieve details of shared mailboxes from Azure AD (Condition B: Pass/Fail)
$sharedMailboxDetails = $users | Where-Object {$_.objectid -in $objectids} $sharedMailboxDetails = $users | Where-Object {$_.id -in $objectids}
# Step: Identify enabled mailboxes (Condition B: Pass/Fail) # Step: Identify enabled mailboxes (Condition B: Pass/Fail)
$enabledMailboxes = $sharedMailboxDetails | Where-Object { $_.AccountEnabled } | ForEach-Object { $_.DisplayName } $enabledMailboxes = $sharedMailboxDetails | Where-Object { $_.AccountEnabled } | ForEach-Object { $_.DisplayName }
$allBlocked = $enabledMailboxes.Count -eq 0 $allBlocked = $enabledMailboxes.Count -eq 0

View File

@@ -5,12 +5,14 @@ function Test-ExternalSharingCalendars {
# Aligned # Aligned
# Parameters can be added if needed # Parameters can be added if needed
) )
begin { begin {
# Dot source the class script if necessary # Dot source the class script if necessary
#. .\source\Classes\CISAuditResult.ps1 #. .\source\Classes\CISAuditResult.ps1
# Initialization code, if needed # Initialization code, if needed
$recnum = "1.3.3" $recnum = "1.3.3"
Write-Verbose "Running Test-ExternalSharingCalendars for $recnum..."
# Conditions for 1.3.3 (L2) Ensure 'External sharing' of calendars is not available (Automated) # Conditions for 1.3.3 (L2) Ensure 'External sharing' of calendars is not available (Automated)
# #
# Validate test for a pass: # Validate test for a pass:
@@ -25,19 +27,12 @@ function Test-ExternalSharingCalendars {
# - Condition A: In the Microsoft 365 admin center, external calendar sharing is enabled. # - Condition A: In the Microsoft 365 admin center, external calendar sharing is enabled.
# - Condition B: Using the Exchange Online PowerShell Module, the `OrganizationConfig` property `ExternalSharingEnabled` is set to `True`. # - Condition B: Using the Exchange Online PowerShell Module, the `OrganizationConfig` property `ExternalSharingEnabled` is set to `True`.
} }
process { process {
try { try {
# Step: Retrieve sharing policies related to calendar sharing # Step: Retrieve sharing policies related to calendar sharing
# $sharingPolicies Mock Object
<#
$sharingPolicies = [PSCustomObject]@{
Name = "Default Sharing Policy"
Domains = @("Anonymous:CalendarSharingFreeBusySimple")
Enabled = $true
Default = $true
}
#>
$sharingPolicies = Get-CISExoOutput -Rec $recnum $sharingPolicies = Get-CISExoOutput -Rec $recnum
# Step (Condition A & B: Pass/Fail): Check if calendar sharing is disabled in all applicable policies # Step (Condition A & B: Pass/Fail): Check if calendar sharing is disabled in all applicable policies
$isExternalSharingDisabled = $true $isExternalSharingDisabled = $true
$sharingPolicyDetails = @() $sharingPolicyDetails = @()
@@ -47,43 +42,47 @@ function Test-ExternalSharingCalendars {
$sharingPolicyDetails += "$($policy.Name): Enabled" $sharingPolicyDetails += "$($policy.Name): Enabled"
} }
} }
# Retrieve calendars with publishing enabled (from 1.3.3b) $failureRemediation = @'
# $calendarDetails Mock Object # Get all mailboxes
<# $mailboxes = Get-Mailbox -ResultSize Unlimited
$calendarDetails = @(
[PSCustomObject]@{ # Initialize a hashtable to store calendar folder names
Calendar = "SMBuser1@domain.com" $calendarFolders = @{}
URL = "https://example.com/calendar/smbuser1" # Get the default calendar folder names for all mailboxes
}, $mailboxes | ForEach-Object {
[PSCustomObject]@{ $calendarFolderName = [string](Get-EXOMailboxFolderStatistics $_.PrimarySmtpAddress -FolderScope Calendar | Where-Object { $_.FolderType -eq 'Calendar' }).Name
Calendar = "SMBuser2@domain.com" $calendarFolders[$_.PrimarySmtpAddress] = $calendarFolderName
URL = "https://example.com/calendar/smbuser2" }
}, # Get the calendar folder settings for each mailbox
[PSCustomObject]@{ foreach ($mailbox in $mailboxes) {
Calendar = "SMBuser4@domain.com" $primarySmtpAddress = $mailbox.PrimarySmtpAddress
URL = "https://example.com/calendar/smbuser3" $calendarFolder = $calendarFolders[$primarySmtpAddress]
# Get users calendar folder settings for their default Calendar folder
$calendar = Get-MailboxCalendarFolder -Identity "$primarySmtpAddress:\$calendarFolder"
# Check if calendar publishing is enabled and display a message
if ($calendar.PublishEnabled) {
Write-Host -ForegroundColor Yellow "Calendar publishing is enabled for $primarySmtpAddress on $($calendar.PublishedCalendarUrl)"
} }
) }
#> '@
$calendarDetails = Get-CISExoOutput -Rec "$("$recnum" + "b")" # Step: Prepare failure reasons and details based on compliance (Condition A & B: Fail)
# Build the failure reason string
$failureReasons = if (-not $isExternalSharingDisabled) { $failureReasons = if (-not $isExternalSharingDisabled) {
$baseMessage = "Calendar sharing with external users is enabled in one or more policies." "Calendar sharing with external users is enabled in one or more policies.`n`n" + `
if ($calendarDetails.Count -gt 0) { "Use the following command to verify which users are sharing calendars prior to disabling:`n`n" + `
$baseMessage += "`nPrior to remediating, check the following mailboxes that have calendar publishing enabled: `n$($calendarDetails -join '`n')" $failureRemediation
}
$baseMessage
} }
else { else {
"N/A" "N/A"
} }
# Step: Prepare details for the audit result (Condition A & B: Pass/Fail) # Step: Prepare details for the audit result (Condition A & B: Pass/Fail)
$details = if ($isExternalSharingDisabled) { $details = if ($isExternalSharingDisabled) {
"Calendar sharing with external users is disabled." "Calendar sharing with external users is disabled."
} }
else { else {
"Enabled Sharing Policies:`n$($sharingPolicyDetails -join ', ')" "Enabled Sharing Policies: $($sharingPolicyDetails -join ', ')"
} }
# Step: Create and populate the CISAuditResult object # Step: Create and populate the CISAuditResult object
$params = @{ $params = @{
Rec = $recnum Rec = $recnum
@@ -99,6 +98,7 @@ function Test-ExternalSharingCalendars {
$auditResult = Get-TestError -LastError $LastError -recnum $recnum $auditResult = Get-TestError -LastError $LastError -recnum $recnum
} }
} }
end { end {
# Return the audit result # Return the audit result
return $auditResult return $auditResult

View File

@@ -24,13 +24,15 @@ function Test-MailboxAuditingE3 {
#> #>
# Dot source the class script if necessary # Dot source the class script if necessary
#. .\source\Classes\CISAuditResult.ps1 #. .\source\Classes\CISAuditResult.ps1
$actionDictionaries = Get-Action -Dictionaries
# E3 specific actions
$AdminActions = $actionDictionaries.AdminActions.Keys | Where-Object { $_ -notin @("MailItemsAccessed", "Send") }
$DelegateActions = $actionDictionaries.DelegateActions.Keys | Where-Object { $_ -notin @("MailItemsAccessed") }
$OwnerActions = $actionDictionaries.OwnerActions.Keys | Where-Object { $_ -notin @("MailItemsAccessed", "Send") }
$allFailures = @()
$recnum = "6.1.2" $recnum = "6.1.2"
$version = $recnum
$actionDictionaries = Get-Action -Dictionaries -Version $version
# E3 specific actions
$AdminActions = $actionDictionaries.AdminActions.Keys
$DelegateActions = $actionDictionaries.DelegateActions.Keys
$OwnerActions = $actionDictionaries.OwnerActions.Keys
$allFailures = @()
Write-Verbose "Running Test-MailboxAuditingE3 for $recnum..." Write-Verbose "Running Test-MailboxAuditingE3 for $recnum..."
$allUsers = Get-CISMgOutput -Rec $recnum $allUsers = Get-CISMgOutput -Rec $recnum
$processedUsers = @{} # Dictionary to track processed users $processedUsers = @{} # Dictionary to track processed users
@@ -52,17 +54,17 @@ function Test-MailboxAuditingE3 {
if ($mailbox.AuditEnabled) { if ($mailbox.AuditEnabled) {
foreach ($action in $AdminActions) { foreach ($action in $AdminActions) {
if ($mailbox.AuditAdmin -notcontains $action) { if ($mailbox.AuditAdmin -notcontains $action) {
$missingAdminActions += (Get-Action -Actions $action -ActionType "Admin") $missingAdminActions += (Get-Action -Actions $action -ActionType "Admin" -Version $version)
} }
} }
foreach ($action in $DelegateActions) { foreach ($action in $DelegateActions) {
if ($mailbox.AuditDelegate -notcontains $action) { if ($mailbox.AuditDelegate -notcontains $action) {
$missingDelegateActions += (Get-Action -Actions $action -ActionType "Delegate") $missingDelegateActions += (Get-Action -Actions $action -ActionType "Delegate" -Version $version)
} }
} }
foreach ($action in $OwnerActions) { foreach ($action in $OwnerActions) {
if ($mailbox.AuditOwner -notcontains $action) { if ($mailbox.AuditOwner -notcontains $action) {
$missingOwnerActions += (Get-Action -Actions $action -ActionType "Owner") $missingOwnerActions += (Get-Action -Actions $action -ActionType "Owner" -Version $version)
} }
} }
if ($missingAdminActions.Count -gt 0 -or $missingDelegateActions.Count -gt 0 -or $missingOwnerActions.Count -gt 0) { if ($missingAdminActions.Count -gt 0 -or $missingDelegateActions.Count -gt 0 -or $missingOwnerActions.Count -gt 0) {
@@ -99,7 +101,7 @@ function Test-MailboxAuditingE3 {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
# Retrieve the description from the test definitions # Retrieve the description from the test definitions
$testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum }
$description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" }

View File

@@ -24,13 +24,14 @@ function Test-MailboxAuditingE5 {
# - Condition B: AuditAdmin actions do not include all of the following: ApplyRecord, Create, HardDelete, MailItemsAccessed, MoveToDeletedItems, Send, SendAs, SendOnBehalf, SoftDelete, Update, UpdateCalendarDelegation, UpdateFolderPermissions, UpdateInboxRules. # - Condition B: AuditAdmin actions do not include all of the following: ApplyRecord, Create, HardDelete, MailItemsAccessed, MoveToDeletedItems, Send, SendAs, SendOnBehalf, SoftDelete, Update, UpdateCalendarDelegation, UpdateFolderPermissions, UpdateInboxRules.
# - Condition C: AuditDelegate actions do not include all of the following: ApplyRecord, Create, HardDelete, MailItemsAccessed, MoveToDeletedItems, SendAs, SendOnBehalf, SoftDelete, Update, UpdateFolderPermissions, UpdateInboxRules. # - Condition C: AuditDelegate actions do not include all of the following: ApplyRecord, Create, HardDelete, MailItemsAccessed, MoveToDeletedItems, SendAs, SendOnBehalf, SoftDelete, Update, UpdateFolderPermissions, UpdateInboxRules.
# - Condition D: AuditOwner actions do not include all of the following: ApplyRecord, HardDelete, MailItemsAccessed, MoveToDeletedItems, Send, SoftDelete, Update, UpdateCalendarDelegation, UpdateFolderPermissions, UpdateInboxRules. # - Condition D: AuditOwner actions do not include all of the following: ApplyRecord, HardDelete, MailItemsAccessed, MoveToDeletedItems, Send, SoftDelete, Update, UpdateCalendarDelegation, UpdateFolderPermissions, UpdateInboxRules.
$actionDictionaries = Get-Action -Dictionaries $recnum = "6.1.3"
$version = $recnum
$actionDictionaries = Get-Action -Dictionaries -Version $version
$AdminActions = $actionDictionaries.AdminActions.Keys $AdminActions = $actionDictionaries.AdminActions.Keys
$DelegateActions = $actionDictionaries.DelegateActions.Keys $DelegateActions = $actionDictionaries.DelegateActions.Keys
$OwnerActions = $actionDictionaries.OwnerActions.Keys $OwnerActions = $actionDictionaries.OwnerActions.Keys
$allFailures = @() $allFailures = @()
$processedUsers = @{} $processedUsers = @{}
$recnum = "6.1.3"
Write-Verbose "Running Test-MailboxAuditingE5 for $recnum..." Write-Verbose "Running Test-MailboxAuditingE5 for $recnum..."
$allUsers = Get-CISMgOutput -Rec $recnum $allUsers = Get-CISMgOutput -Rec $recnum
} }
@@ -52,19 +53,19 @@ function Test-MailboxAuditingE5 {
# Validate Admin actions # Validate Admin actions
foreach ($action in $AdminActions) { foreach ($action in $AdminActions) {
if ($mailbox.AuditAdmin -notcontains $action) { if ($mailbox.AuditAdmin -notcontains $action) {
$missingAdminActions += (Get-Action -Actions $action -ActionType "Admin") # Condition B $missingAdminActions += (Get-Action -Actions $action -ActionType "Admin" -Version $version) # Condition B
} }
} }
# Validate Delegate actions # Validate Delegate actions
foreach ($action in $DelegateActions) { foreach ($action in $DelegateActions) {
if ($mailbox.AuditDelegate -notcontains $action) { if ($mailbox.AuditDelegate -notcontains $action) {
$missingDelegateActions += (Get-Action -Actions $action -ActionType "Delegate") # Condition C $missingDelegateActions += (Get-Action -Actions $action -ActionType "Delegate" -Version $version) # Condition C
} }
} }
# Validate Owner actions # Validate Owner actions
foreach ($action in $OwnerActions) { foreach ($action in $OwnerActions) {
if ($mailbox.AuditOwner -notcontains $action) { if ($mailbox.AuditOwner -notcontains $action) {
$missingOwnerActions += (Get-Action -Actions $action -ActionType "Owner") # Condition D $missingOwnerActions += (Get-Action -Actions $action -ActionType "Owner" -Version $version) # Condition D
} }
} }
if ($missingAdminActions.Count -gt 0 -or $missingDelegateActions.Count -gt 0 -or $missingOwnerActions.Count -gt 0) { if ($missingAdminActions.Count -gt 0 -or $missingDelegateActions.Count -gt 0 -or $missingOwnerActions.Count -gt 0) {
@@ -102,7 +103,7 @@ function Test-MailboxAuditingE5 {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
# Retrieve the description from the test definitions # Retrieve the description from the test definitions
$testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum }
$description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" }

View File

@@ -45,13 +45,12 @@ function Test-PasswordNeverExpirePolicy {
$isDefault = $domain.IsDefault $isDefault = $domain.IsDefault
# Step (Condition C): Determine if the notification window is set to 30 days # Step (Condition C): Determine if the notification window is set to 30 days
$notificationWindow = $domain.PasswordNotificationWindowInDays $notificationWindow = $domain.PasswordNotificationWindowInDays
$notificationPolIsCompliant = $notificationWindow -eq 30 $notificationPolIsCompliant = $true # No longer a requirement
# Step (Condition A): Retrieve password expiration policy # Step (Condition A): Retrieve password expiration policy
$passwordPolicy = $domain.PasswordValidityPeriodInDays $passwordPolicy = $domain.PasswordValidityPeriodInDays
$pwPolIsCompliant = $passwordPolicy -eq 2147483647 $pwPolIsCompliant = $passwordPolicy -eq 2147483647
# Step (Condition A & B): Determine if the policy is compliant # Step (Condition A & B): Determine if the policy is compliant
$overallResult = $overallResult -and $notificationPolIsCompliant -and $pwPolIsCompliant $overallResult = $overallResult -and $notificationPolIsCompliant -and $pwPolIsCompliant
# Step (Condition A & B): Prepare failure reasons and details based on compliance # Step (Condition A & B): Prepare failure reasons and details based on compliance
$failureReasons = if ($notificationPolIsCompliant -and $pwPolIsCompliant) { $failureReasons = if ($notificationPolIsCompliant -and $pwPolIsCompliant) {
"N/A" "N/A"
@@ -59,18 +58,14 @@ function Test-PasswordNeverExpirePolicy {
else { else {
"Password expiration is not set to never expire or notification window is not set to 30 days for domain $domainName. Run the following command to remediate: `nUpdate-MgDomain -DomainId $domainName -PasswordValidityPeriodInDays 2147483647 -PasswordNotificationWindowInDays 30`n" "Password expiration is not set to never expire or notification window is not set to 30 days for domain $domainName. Run the following command to remediate: `nUpdate-MgDomain -DomainId $domainName -PasswordValidityPeriodInDays 2147483647 -PasswordNotificationWindowInDays 30`n"
} }
$details = "$domainName|$passwordPolicy days|$notificationWindow days|$isDefault" $details = "$domainName|$passwordPolicy days|$notificationWindow days|$isDefault"
# Add details and failure reasons to the lists # Add details and failure reasons to the lists
$detailsList += $details $detailsList += $details
$failureReasonsList += $failureReasons $failureReasonsList += $failureReasons
} }
# Prepare the final failure reason and details # Prepare the final failure reason and details
$finalFailureReason = $failureReasonsList -join "`n" $finalFailureReason = $failureReasonsList -join "`n"
$finalDetails = $detailsList -join "`n" $finalDetails = $detailsList -join "`n"
# Step: Create and populate the CISAuditResult object # Step: Create and populate the CISAuditResult object
$params = @{ $params = @{
Rec = $recnum Rec = $recnum
@@ -86,7 +81,6 @@ function Test-PasswordNeverExpirePolicy {
$auditResult = Get-TestError -LastError $LastError -recnum $recnum $auditResult = Get-TestError -LastError $LastError -recnum $recnum
} }
} }
end { end {
# Return the audit result # Return the audit result
return $auditResult return $auditResult

View File

@@ -1,19 +1,22 @@
function Test-SafeAttachmentsPolicy { function Test-SafeAttachmentsPolicy {
[CmdletBinding()] [CmdletBinding()]
[OutputType([CISAuditResult])] [OutputType([CISAuditResult])]
param () param (
[Parameter(Mandatory = $false)]
[string]$DomainName
)
begin { begin {
$recnum = "2.1.4" $recnum = "2.1.4"
Write-Verbose "Running Test-SafeAttachmentsPolicy for $recnum..." Write-Verbose "Running Test-SafeAttachmentsPolicy for $recnum..."
<# <#
Conditions for 2.1.4 (L2) Ensure Safe Attachments policy is enabled: Conditions for 2.1.4 (L2) Ensure Safe Attachments policy is enabled:
Validate test for a pass: Validate test for a pass:
- Ensure the highest priority Safe Attachments policy is enabled. - Ensure Safe Attachments policies are enabled.
- Check if the policy's action is set to 'Block'. - Check if each policy's action is set to 'Block'.
- Confirm the QuarantineTag is set to 'AdminOnlyAccessPolicy'. - Confirm the QuarantineTag is set to 'AdminOnlyAccessPolicy'.
- Verify that the Redirect setting is disabled. - Verify that the Redirect setting is disabled.
Validate test for a fail: Validate test for a fail:
- If the highest priority Safe Attachments policy's action is not set to 'Block'. - If any Safe Attachments policy's action is not set to 'Block'.
- If the QuarantineTag is not set to 'AdminOnlyAccessPolicy'. - If the QuarantineTag is not set to 'AdminOnlyAccessPolicy'.
- If the Redirect setting is enabled. - If the Redirect setting is enabled.
- If no enabled Safe Attachments policies are found. - If no enabled Safe Attachments policies are found.
@@ -33,35 +36,47 @@ function Test-SafeAttachmentsPolicy {
} }
) )
#> #>
$safeAttachmentPolicies = Get-CISExoOutput -Rec $recnum $safeAttachmentPolicies, $safeAttachmentRules = Get-CISExoOutput -Rec $recnum
$safeAttachmentPolicies = $safeAttachmentPolicies | Where-Object { $_.Identity -in $safeAttachmentRules.SafeAttachmentPolicy }
if ($safeAttachmentPolicies -ne 1) { if ($safeAttachmentPolicies -ne 1) {
try { try {
$highestPriorityPolicy = $safeAttachmentPolicies | Select-Object -First 1 if ($DomainName) {
$safeAttachmentPolicies = $safeAttachmentPolicies | Where-Object { $_.Identity -eq ($safeAttachmentRules | Sort-Object -Property Priority | Where-Object { $_.RecipientDomainIs -in $DomainName } | Select-Object -ExpandProperty SafeAttachmentPolicy -First 1) }
$RecipientDomains = $safeAttachmentRules | Where-Object { $_.SafeAttachmentPolicy -eq $safeAttachmentPolicies.Identity } | Select-Object -ExpandProperty RecipientDomainIs
}
# Initialize details and failure reasons # Initialize details and failure reasons
$details = @() $details = @()
$failureReasons = @() $failureReasons = @()
foreach ($policy in $safeAttachmentPolicies) {
# Check policy specifics as per CIS benchmark requirements # Check policy specifics as per CIS benchmark requirements
if ($highestPriorityPolicy.Action -ne 'Block') { if ($Policy.Action -ne 'Block') {
$failureReasons += "Policy action is not set to 'Block'." $failureReasons += "Policy: $($Policy.Identity); Action is not set to 'Block'."
} }
if ($highestPriorityPolicy.QuarantineTag -ne 'AdminOnlyAccessPolicy') { if ($Policy.QuarantineTag -ne 'AdminOnlyAccessPolicy') {
$failureReasons += "Quarantine policy is not set to 'AdminOnlyAccessPolicy'." $failureReasons += "Policy: $($Policy.Identity); Quarantine is not set to 'AdminOnlyAccessPolicy'."
} }
if ($highestPriorityPolicy.Redirect -ne $false) { if ($Policy.Redirect -ne $false) {
$failureReasons += "Redirect is not disabled." $failureReasons += "Policy: $($Policy.Identity); Redirect is not disabled."
} }
# The result is a pass if there are no failure reasons # The result is a pass if there are no failure reasons
$details += [PSCustomObject]@{
Policy = ($Policy.Identity).trim()
Action = $Policy.Action
QuarantineTag = $Policy.QuarantineTag
Redirect = $Policy.Redirect
Enabled = $Policy.Enable
Priority = [int]($safeAttachmentRules | Where-Object { $_.SafeAttachmentPolicy -eq $Policy.Identity } | Select-Object -ExpandProperty Priority)
}
}
$result = $failureReasons.Count -eq 0 $result = $failureReasons.Count -eq 0
$details = [PSCustomObject]@{ if ($RecipientDomains) {
Policy = $highestPriorityPolicy.Identity $failureReasons += "Recipient domain(s): '$($RecipientDomains -join ', ' )' included in tested policy."
Action = $highestPriorityPolicy.Action
QuarantineTag = $highestPriorityPolicy.QuarantineTag
Redirect = $highestPriorityPolicy.Redirect
Enabled = $highestPriorityPolicy.Enable
} }
# Format details for output manually # Format details for output manually
$detailsString = "Policy|Action|QuarantineTag|Redirect|Enabled`n" + ($details | $detailsString = "Policy|Action|QuarantineTag|Redirect|Enabled|Priority`n" + `
ForEach-Object { "$($_.Policy)|$($_.Action)|$($_.QuarantineTag)|$($_.Redirect)|$($_.Enabled)`n" } ($details | ForEach-Object {
"$($_.Policy)|$($_.Action)|$($_.QuarantineTag)|$($_.Redirect)|$($_.Enabled)|$($_.Priority)`n"
}
) )
$failureReasonsString = ($failureReasons -join "`n") $failureReasonsString = ($failureReasons -join "`n")
# Create and populate the CISAuditResult object # Create and populate the CISAuditResult object
@@ -75,7 +90,7 @@ function Test-SafeAttachmentsPolicy {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
# Retrieve the description from the test definitions # Retrieve the description from the test definitions
$testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum }
$description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" }

View File

@@ -88,7 +88,7 @@ AllowSafeDocsOpen: $($_.AllowSafeDocsOpen)
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
# Retrieve the description from the test definitions # Retrieve the description from the test definitions
$testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum }
$description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" }

View File

@@ -58,7 +58,7 @@ function Test-SafeLinksOfficeApps {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
# Retrieve the description from the test definitions # Retrieve the description from the test definitions
$testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum } $testDefinition = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $recnum }
$description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" } $description = if ($testDefinition) { $testDefinition.RecDescription } else { "Description not found" }

View File

@@ -108,7 +108,7 @@ function Test-SpamPolicyAdminNotify {
$auditResult = Initialize-CISAuditResult @params $auditResult = Initialize-CISAuditResult @params
} }
catch { catch {
Write-Error "An error occurred during the test: $_" Write-Error "An error occurred during the test $recnum`:: $_"
$auditResult = Get-TestError -LastError $_ -recnum $recnum $auditResult = Get-TestError -LastError $_ -recnum $recnum
} }
} }

View File

@@ -0,0 +1,27 @@
$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path
$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
$(try { Test-ModuleManifest $_.FullName -ErrorAction Stop } catch { $false } )
}).BaseName
Import-Module $ProjectName
InModuleScope $ProjectName {
Describe Get-PrivateFunction {
Context 'Default' {
BeforeEach {
$return = Get-PrivateFunction -PrivateData 'string'
}
It 'Returns a single object' {
($return | Measure-Object).Count | Should -Be 1
}
It 'Returns a string based on the parameter PrivateData' {
$return | Should -Be 'string'
}
}
}
}