Skip to content

Gereral testing enhancements. #119

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b18780d
fix: Update 1.3.1 output and test logic to include notification window.
DrIOSX Jun 20, 2024
359d289
docs: Update CHANGELOG
DrIOSX Jun 20, 2024
ab0ef53
add: Export to excel option for table exports
DrIOSX Jun 20, 2024
1d46257
docs: Update CHANGELOG
DrIOSX Jun 20, 2024
0f3587a
docs: Update README and Help
DrIOSX Jun 20, 2024
f5f6d39
add: skip msol connnection for Get-MFAStatus
DrIOSX Jun 23, 2024
84c16ac
fix 6.1.1 test definition so it uses EXO
DrIOSX Jun 23, 2024
39ba3c3
add: New process for collecting MgGraph output to make pester testing…
DrIOSX Jun 23, 2024
5ff2396
fix: Removed banner from EXO connection step
DrIOSX Jun 23, 2024
b564458
fix: Removed banner fix and included AzureAD
DrIOSX Jun 23, 2024
736997f
add: Get-ExoOutput function and modified tests: '1.2.2', '1.3.3', '1.…
DrIOSX Jun 23, 2024
c578045
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
90c5b95
fix: missing output type comments for switches
DrIOSX Jun 23, 2024
381b8eb
add: Get-ExoOutput function and updated tests
DrIOSX Jun 23, 2024
9a299d4
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
a90df5b
docs: Update Formatting
DrIOSX Jun 23, 2024
e9bac2f
changed name of output functions with prefix 'CIS'
DrIOSX Jun 23, 2024
7e98f77
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
a874836
fix: Update formatting
DrIOSX Jun 23, 2024
917833b
add: Get-CISMSTeamsOutput function and updated respective tests
DrIOSX Jun 23, 2024
6b135c2
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
b6423c8
Update output for Connect-SPOService
DrIOSX Jun 23, 2024
4dd65a0
add: Error handling to output functions
DrIOSX Jun 23, 2024
bad103f
add: Get-CISSpoOutput function and updated respective tests
DrIOSX Jun 23, 2024
0601996
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
6b94ee7
add: Get-CISAadOutput function and updated respective tests
DrIOSX Jun 23, 2024
e60c985
fix: output functions verbosity
DrIOSX Jun 23, 2024
be68c1d
fix: Remove output type for output functions. Add Later
DrIOSX Jun 23, 2024
defcf56
add: DomainName paramter to get-mggraph and test 1.3.1
DrIOSX Jun 23, 2024
1e75fbd
add: DomainName paramter to get-mggraph and test 1.3.1
DrIOSX Jun 23, 2024
a141380
add: simplified error handling with Get-TestError
DrIOSX Jun 23, 2024
011f91c
docs: Update CHANGELOG
DrIOSX Jun 23, 2024
82df166
docs: Update CommentBlock for Remove-RowsWithEmptyCSVStatus
DrIOSX Jun 23, 2024
ca17343
docs: Update CHANGELOG and Help Uri
DrIOSX Jun 23, 2024
4e0b20f
fix: Test-Error verbose call and Get-CISMgOutput Parameter
DrIOSX Jun 23, 2024
e81395b
fix: Connect host output
DrIOSX Jun 23, 2024
6dc52f5
docs: Formatting Invoke-M365SecurityAudit
DrIOSX Jun 23, 2024
968e589
add: finally block to always disconnect
DrIOSX Jun 23, 2024
8b91a8c
add: finally block to always disconnect
DrIOSX Jun 23, 2024
5c85267
add: finally block to always disconnect
DrIOSX Jun 24, 2024
e043668
docs: formatting
DrIOSX Jun 24, 2024
e6cdae3
docs: Update CHANGELOG
DrIOSX Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ The format is based on and uses the types of changes according to [Keep a Change

## [Unreleased]

### Fixed

- Fixed test 1.3.1 to include notification window for password expiration.
- Fixed 6.1.1 test definition to include the correct connection.
- Removed banner and warning from EXO and AzureAD connection step.
- Fixed missing CommentBlock for `Remove-RowsWithEmptyCSVStatus` function.
- Fixed formatting and color for various Write-Host messages.

### Added

- Added export to excel to `Export-M365SecurityAuditTable` function.
- `Get-AdminRoleUserLicense` function to get the license of a user with admin roles for 1.1.1.
- Skip MSOL connection confirmation to `Get-MFAStatus` function.
- Added `Get-CISMgOutput` function to get the output of the Microsoft Graph API per test.
- Added `Get-CISExoOutput` function to get the output of the Exchange Online API per test.
- Added `Get-CISMSTeamsOutput` function to get the output of the Microsoft Teams API per test.
- Added `Get-CISSPOOutput` function to get the output of the SharePoint Online API per test.
- Added `Get-TestError` function to get the error output of a test.
- Updated Microsoft Graph tests to utilize the new output functions ('1.1.1', '1.1.3', '1.2.1', '1.3.1', '5.1.2.3', '5.1.8.1', '6.1.2', '6.1.3')
- Updated EXO tests to utilize the new output functions ('1.2.2', '1.3.3', '1.3.6', '2.1.1', '2.1.2', '2.1.3', '2.1.4', '2.1.5', '2.1.6', '2.1.7', '2.1.9', '3.1.1', '6.1.1', '6.1.2', '6.1.3', '6.2.1', '6.2.2', '6.2.3', '6.3.1', '6.5.1', '6.5.2', '6.5.3', '8.6.1').
- Updated MSTeams tests to utilize the new output functions ('8.1.1', '8.1.2', '8.2.1', '8.5.1', '8.5.2', '8.5.3', '8.5.4', '8.5.5', '8.5.6', '8.5.7', '8.6.1')
- Updated SPO tests to utilize the new output functions ('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')

## [0.1.13] - 2024-06-18

### Added

- Added tenant output to connect function.
Expand Down
Binary file modified README.md
Binary file not shown.
Binary file modified docs/index.html
Binary file not shown.
12 changes: 6 additions & 6 deletions source/Private/Assert-ModuleAvailability.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ function Assert-ModuleAvailability {
$module = Get-Module -ListAvailable -Name $ModuleName | Where-Object { $_.Version -ge [version]$RequiredVersion }

if ($null -eq $module) {
Write-Information "Installing $ModuleName module..." -InformationAction Continue
Write-Host "Installing $ModuleName module..." -ForegroundColor Yellow
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force -AllowClobber -Scope CurrentUser | Out-Null
}
elseif ($module.Version -lt [version]$RequiredVersion) {
Write-Information "Updating $ModuleName module to required version..." -InformationAction Continue
Write-Host "Updating $ModuleName module to required version..." -ForegroundColor Yellow
Update-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force | Out-Null
}
else {
Write-Information "$ModuleName module is already at required version or newer." -InformationAction Continue
Write-Host "$ModuleName module is already at required version or newer." -ForegroundColor Gray
}

if ($SubModules.Count -gt 0) {
foreach ($subModule in $SubModules) {
Write-Information "Importing submodule $ModuleName.$subModule..." -InformationAction Continue
Write-Host "Importing submodule $ModuleName.$subModule..." -ForegroundColor DarkGray
Import-Module -Name "$ModuleName.$subModule" -RequiredVersion $RequiredVersion -ErrorAction Stop | Out-Null
}
} else {
Write-Information "Importing module $ModuleName..." -InformationAction Continue
Import-Module -Name $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop | Out-Null
Write-Host "Importing module $ModuleName..." -ForegroundColor DarkGray
Import-Module -Name $ModuleName -RequiredVersion $RequiredVersion -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null
}
}
catch {
Expand Down
25 changes: 12 additions & 13 deletions source/Private/Connect-M365Suite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function Connect-M365Suite {

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 Cyan
Connect-AzureAD | Out-Null
$tenantDetails = Get-AzureADTenantDetail
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
Expand All @@ -31,7 +31,7 @@ function Connect-M365Suite {
}

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 Cyan
Write-Host "Connecting to Microsoft Graph with scopes: Directory.Read.All, Domain.Read.All, Policy.Read.All, Organization.Read.All" -ForegroundColor Yellow
try {
Connect-MgGraph -Scopes "Directory.Read.All", "Domain.Read.All", "Policy.Read.All", "Organization.Read.All" -NoWelcome | Out-Null
$graphOrgDetails = Get-MgOrganization
Expand All @@ -58,8 +58,8 @@ function Connect-M365Suite {
}

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 Cyan
Connect-ExchangeOnline | Out-Null
Write-Host "Connecting to Exchange Online..." -ForegroundColor Yellow
Connect-ExchangeOnline -ShowBanner:$false | Out-Null
$exoTenant = (Get-OrganizationConfig).Identity
$tenantInfo += [PSCustomObject]@{
Service = "Exchange Online"
Expand All @@ -71,20 +71,20 @@ function Connect-M365Suite {
}

if ($RequiredConnections -contains "SPO") {
Write-Host "Connecting to SharePoint Online..." -ForegroundColor Cyan
Write-Host "Connecting to SharePoint Online..." -ForegroundColor Yellow
Connect-SPOService -Url $TenantAdminUrl | Out-Null
$spoContext = Get-SPOSite -Limit 1
$spoContext = Get-SPOCrossTenantHostUrl
$tenantName = Get-UrlLine -Output $spoContext
$tenantInfo += [PSCustomObject]@{
Service = "SharePoint Online"
TenantName = $spoContext.Url
TenantID = $spoContext.GroupId
TenantName = $tenantName
}
$connectedServices += "SPO"
Write-Host "Successfully connected to SharePoint Online." -ForegroundColor Green
}

if ($RequiredConnections -contains "Microsoft Teams" -or $RequiredConnections -contains "Microsoft Teams | EXO") {
Write-Host "Connecting to Microsoft Teams..." -ForegroundColor Cyan
Write-Host "Connecting to Microsoft Teams..." -ForegroundColor Yellow
Connect-MicrosoftTeams | Out-Null
$teamsTenantDetails = Get-CsTenant
$tenantInfo += [PSCustomObject]@{
Expand All @@ -101,9 +101,8 @@ function Connect-M365Suite {
Write-Host "Connected to the following tenants:" -ForegroundColor Yellow
foreach ($tenant in $tenantInfo) {
Write-Host "Service: $($tenant.Service)" -ForegroundColor Cyan
Write-Host "Tenant Name: $($tenant.TenantName)" -ForegroundColor Green
Write-Host "Tenant Context: $($tenant.TenantName)`n" -ForegroundColor Green
#Write-Host "Tenant ID: $($tenant.TenantID)"
Write-Host ""
}
$confirmation = Read-Host "Do you want to proceed with these connections? (Y/N)"
if ($confirmation -notlike 'Y') {
Expand Down
38 changes: 38 additions & 0 deletions source/Private/Get-AdminRoleUserAndAssignment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function Get-AdminRoleUserAndAssignment {
[CmdletBinding()]
param ()

$result = @{}

# Get the DisplayNames of all admin roles
$adminRoleNames = (Get-MgDirectoryRole | Where-Object { $null -ne $_.RoleTemplateId }).DisplayName

# Get Admin Roles
$adminRoles = Get-MgRoleManagementDirectoryRoleDefinition | Where-Object { ($adminRoleNames -contains $_.DisplayName) -and ($_.DisplayName -ne "Directory Synchronization Accounts") }

foreach ($role in $adminRoles) {
Write-Verbose "Processing role: $($role.DisplayName)"
$roleAssignments = Get-MgRoleManagementDirectoryRoleAssignment -Filter "roleDefinitionId eq '$($role.Id)'"

foreach ($assignment in $roleAssignments) {
Write-Verbose "Processing role assignment for principal ID: $($assignment.PrincipalId)"
$userDetails = Get-MgUser -UserId $assignment.PrincipalId -Property "DisplayName, UserPrincipalName, Id, OnPremisesSyncEnabled" -ErrorAction SilentlyContinue

if ($userDetails) {
Write-Verbose "Retrieved user details for: $($userDetails.UserPrincipalName)"
$licenses = Get-MgUserLicenseDetail -UserId $assignment.PrincipalId -ErrorAction SilentlyContinue

if (-not $result[$role.DisplayName]) {
$result[$role.DisplayName] = @()
}
$result[$role.DisplayName] += [PSCustomObject]@{
AssignmentId = $assignment.Id
UserDetails = $userDetails
Licenses = $licenses
}
}
}
}

return $result
}
39 changes: 39 additions & 0 deletions source/Private/Get-CISAadOutput.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
.SYNOPSIS
This is a sample Private function only visible within the module.
.DESCRIPTION
This sample function is not exported to the module and only return the data passed as parameter.
.EXAMPLE
$null = Get-Get-CISAadOutput -PrivateData 'NOTHING TO SEE HERE'
.PARAMETER PrivateData
The PrivateData parameter is what will be returned without transformation.
#>
function Get-CISAadOutput {
[cmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[String]$Rec
)
begin {
# Begin Block #
<#
# Tests
1.2.2
# Test number
$testNumbers ="1.2.2"
#>
}
process {
switch ($Rec) {
'1.2.2' {
# Test-BlockSharedMailboxSignIn.ps1
$users = Get-AzureADUser
}
default { throw "No match found for test: $Rec" }
}
}
end {
Write-Verbose "Get-CISAadOutput: Retuning data for Rec: $Rec"
return $users
}
} # end function Get-CISAadOutput
Loading
Loading