fix: 1.1.3 aligned with test-template
This commit is contained in:
@@ -1,46 +1,59 @@
|
|||||||
function Test-GlobalAdminsCount {
|
function Test-GlobalAdminsCount {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
# Define your parameters here
|
# Aligned
|
||||||
|
# Define your parameters here if needed
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
# Dot source the class script
|
# Dot source the class script if necessary
|
||||||
|
. .\source\Classes\CISAuditResult.ps1
|
||||||
|
|
||||||
$auditResults = @()
|
# Initialization code, if needed
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
# 1.1.3 (L1) Ensure that between two and four global admins are designated
|
# 1.1.3 (L1) Ensure that between two and four global admins are designated
|
||||||
# Pass if the count of global admins is between 2 and 4. Fail otherwise.
|
|
||||||
|
|
||||||
|
# Retrieve global admin role and members
|
||||||
$globalAdminRole = Get-MgDirectoryRole -Filter "RoleTemplateId eq '62e90394-69f5-4237-9190-012177145e10'"
|
$globalAdminRole = Get-MgDirectoryRole -Filter "RoleTemplateId eq '62e90394-69f5-4237-9190-012177145e10'"
|
||||||
$globalAdmins = Get-MgDirectoryRoleMember -DirectoryRoleId $globalAdminRole.Id
|
$globalAdmins = Get-MgDirectoryRoleMember -DirectoryRoleId $globalAdminRole.Id
|
||||||
$globalAdminCount = $globalAdmins.AdditionalProperties.Count
|
$globalAdminCount = $globalAdmins.AdditionalProperties.Count
|
||||||
$globalAdminUsernames = ($globalAdmins | ForEach-Object { $_.AdditionalProperties["displayName"] }) -join ', '
|
$globalAdminUsernames = ($globalAdmins | ForEach-Object { $_.AdditionalProperties["displayName"] }) -join ', '
|
||||||
|
|
||||||
# Create an instance of CISAuditResult and populate it
|
# Prepare failure reasons and details based on compliance
|
||||||
|
$failureReasons = if ($globalAdminCount -lt 2) {
|
||||||
|
"Less than 2 global admins: $globalAdminUsernames"
|
||||||
|
}
|
||||||
|
elseif ($globalAdminCount -gt 4) {
|
||||||
|
"More than 4 global admins: $globalAdminUsernames"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
"N/A"
|
||||||
|
}
|
||||||
|
|
||||||
|
$details = "Count: $globalAdminCount; Users: $globalAdminUsernames"
|
||||||
|
|
||||||
|
# Create and populate the CISAuditResult object
|
||||||
$auditResult = [CISAuditResult]::new()
|
$auditResult = [CISAuditResult]::new()
|
||||||
$auditResult.CISControlVer = "v8"
|
$auditResult.CISControlVer = "v8"
|
||||||
$auditResult.CISControl = "5.1"
|
$auditResult.CISControl = "5.1"
|
||||||
$auditResult.CISDescription = "Establish and Maintain an Inventory of Accounts"
|
$auditResult.CISDescription = "Establish and Maintain an Inventory of Accounts"
|
||||||
$auditResult.Rec = "1.1.3"
|
$auditResult.Rec = "1.1.3"
|
||||||
$auditResult.ELevel = "E3" # Based on your environment (E3, E5, etc.)
|
$auditResult.ELevel = "E3"
|
||||||
$auditResult.ProfileLevel = "L1"
|
$auditResult.ProfileLevel = "L1"
|
||||||
$auditResult.IG1 = $true # Set based on the benchmark
|
$auditResult.IG1 = $true
|
||||||
$auditResult.IG2 = $true # Set based on the benchmark
|
$auditResult.IG2 = $true
|
||||||
$auditResult.IG3 = $true # Set based on the benchmark
|
$auditResult.IG3 = $true
|
||||||
$auditResult.RecDescription = "Ensure that between two and four global admins are designated"
|
$auditResult.RecDescription = "Ensure that between two and four global admins are designated"
|
||||||
$auditResult.Result = $globalAdminCount -ge 2 -and $globalAdminCount -le 4
|
$auditResult.Result = $globalAdminCount -ge 2 -and $globalAdminCount -le 4
|
||||||
$auditResult.Details = "Count: $globalAdminCount; Users: $globalAdminUsernames"
|
$auditResult.Details = $details
|
||||||
$auditResult.FailureReason = if ($globalAdminCount -lt 2) { "Less than 2 global admins: $globalAdminUsernames" } elseif ($globalAdminCount -gt 4) { "More than 4 global admins: $globalAdminUsernames" } else { "N/A" }
|
$auditResult.FailureReason = $failureReasons
|
||||||
$auditResult.Status = if ($globalAdminCount -ge 2 -and $globalAdminCount -le 4) { "Pass" } else { "Fail" }
|
$auditResult.Status = if ($globalAdminCount -ge 2 -and $globalAdminCount -le 4) { "Pass" } else { "Fail" }
|
||||||
|
|
||||||
$auditResults += $auditResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {
|
||||||
# Return auditResults
|
# Return the audit result
|
||||||
return $auditResults
|
return $auditResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user