Skip to content

Commit 9c460ea

Browse files
committed
Adding regular check functions
1 parent b07de9b commit 9c460ea

11 files changed

Lines changed: 861 additions & 2 deletions

365AutomatedCheck.psd1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '365AutomatedCheck.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.0.9'
15+
ModuleVersion = '0.0.10'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
@@ -56,6 +56,7 @@ RequiredModules = @(
5656
@{ ModuleName='ExchangeOnlineManagement'; ModuleVersion='2.0.6' }
5757
@{ ModuleName='Microsoft.Graph.Users'; ModuleVersion='1.17.0' }
5858
@{ ModuleName='Microsoft.Graph.Groups'; ModuleVersion='1.17.0' }
59+
@{ ModuleName='Microsoft.Graph.Beta.Users'; ModuleVersion='2.20.0' }
5960
@{ ModuleName='Microsoft.Graph.Identity.DirectoryManagement'; ModuleVersion='1.17.0' }
6061
@{ ModuleName='Microsoft.Graph.Users.Actions'; ModuleVersion='1.17.0' }
6162
@{ ModuleName='PSFramework'; ModuleVersion='1.8.289' }
@@ -89,7 +90,17 @@ FunctionsToExport = @(
8990
'Test-365ACJobTitle',
9091
'Convert-365ACXmlToHtml',
9192
'Get-365ACPesterConfiguration',
92-
'Set-365ACDefaultOutputPath'
93+
'Set-365ACDefaultOutputPath',
94+
'Test-365ACCountry',
95+
'Test-365ACStreetAddress',
96+
'Test-365ACCity',
97+
'Test-365ACState',
98+
'Test-365ACPostalCode',
99+
'Test-365ACMailNickName',
100+
'Test-365ACAccountEnabled',
101+
'Test-365ACEmployeeID',
102+
'Test-365ACAddressBook',
103+
'Test-365ACLastLogin'
93104
)
94105

95106
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<#
2+
.SYNOPSIS
3+
Tests if users' accounts are enabled in their Microsoft 365 profiles.
4+
5+
.DESCRIPTION
6+
The Test-365ACAccountEnabled function checks each user retrieved from Microsoft 365 to determine if their account is enabled. It processes a list of users, determining the enabled status of each user's account. The results can be exported to an Excel file, an HTML file, or output directly.
7+
8+
.PARAMETER Users
9+
An array of users to be tested. This can be piped in or specified directly. Each user should have DisplayName and AccountEnabled properties.
10+
11+
.PARAMETER OutputExcelFilePath
12+
The file path where the Excel report will be saved. The file must have an .xlsx extension.
13+
14+
.PARAMETER HtmlFilePath
15+
The file path where the HTML report will be saved. The file must have an .html extension.
16+
17+
.PARAMETER TestedProperty
18+
The property being tested. This is set to 'Is Account Enabled' by default.
19+
20+
.EXAMPLE
21+
PS> $users = Get-MgUser -All -Property DisplayName, AccountEnabled | Select-Object DisplayName, AccountEnabled
22+
PS> Test-365ACAccountEnabled -Users $users -OutputExcelFilePath "C:\Reports\AccountEnabledReport.xlsx"
23+
24+
This example retrieves all users with their DisplayName and AccountEnabled status, then tests each user to see if their account is enabled. The results are exported to an Excel file.
25+
26+
.EXAMPLE
27+
PS> Get-MgUser -All -Property DisplayName, AccountEnabled | Select-Object DisplayName, AccountEnabled | Test-365ACAccountEnabled -HtmlFilePath "C:\Reports\AccountEnabledReport.html"
28+
29+
This example pipes a list of users directly into Test-365ACAccountEnabled, which then checks if each user's account is enabled. The results are exported to an HTML file.
30+
31+
.NOTES
32+
This function requires the Microsoft Graph PowerShell SDK to retrieve user information from Microsoft 365.
33+
34+
.LINK
35+
https://docs.microsoft.com/powershell/module/microsoft.graph.users/get-mguser
36+
37+
#>
38+
Function Test-365ACAccountEnabled {
39+
[CmdletBinding()]
40+
param
41+
(
42+
[Parameter(ValueFromPipeline = $true)]
43+
[array]$Users = (Get-MgUser -All -Property DisplayName, AccountEnabled | Select-Object DisplayName, AccountEnabled),
44+
45+
[ValidatePattern('\.xlsx$')]
46+
[string]$OutputExcelFilePath,
47+
48+
[ValidatePattern('\.html$')]
49+
[string]$HtmlFilePath,
50+
51+
[string]$TestedProperty = 'Is Account Enabled'
52+
)
53+
BEGIN {
54+
$results = @()
55+
}
56+
PROCESS {
57+
foreach ($user in $Users) {
58+
$isAccountEnabled = [bool]($user.AccountEnabled)
59+
$result = [PSCustomObject]@{
60+
'User Display Name' = $user.DisplayName
61+
$TestedProperty = $isAccountEnabled
62+
}
63+
$results += $result
64+
}
65+
}
66+
END {
67+
$totalTests = $results.Count
68+
$passedTests = ($results | Where-Object { $_.$TestedProperty }).Count
69+
$failedTests = $totalTests - $passedTests
70+
if ($OutputExcelFilePath) {
71+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
72+
}
73+
elseif ($HtmlFilePath) {
74+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
75+
}
76+
else {
77+
Write-Output $results
78+
}
79+
}
80+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<#
2+
.SYNOPSIS
3+
Tests if users are hidden from the Address Book in their Microsoft 365 profiles.
4+
5+
.DESCRIPTION
6+
The Test-365ACAddressBook function checks each user retrieved from Microsoft 365 to determine if they are hidden from the Address Book. It processes a list of users, checking the 'HiddenFromAddressListsEnabled' property. The results can be exported to an Excel file, an HTML file, or output directly.
7+
8+
.PARAMETER Users
9+
An array of users to be tested. This can be piped in or specified directly. Each user should have DisplayName and HiddenFromAddressListsEnabled properties.
10+
11+
.PARAMETER OutputExcelFilePath
12+
The file path where the Excel report will be saved. The file must have an .xlsx extension.
13+
14+
.PARAMETER HtmlFilePath
15+
The file path where the HTML report will be saved. The file must have an .html extension.
16+
17+
.PARAMETER TestedProperty
18+
The property being tested. This is set to 'HiddenFromAddressBook' by default.
19+
20+
.EXAMPLE
21+
$users = Get-MgUser -All -Property DisplayName, HiddenFromAddressListsEnabled | Select-Object DisplayName, HiddenFromAddressListsEnabled
22+
Test-365ACAddressBook -Users $users -OutputExcelFilePath "C:\Reports\AddressBookReport.xlsx"
23+
This example retrieves all users with their DisplayName and HiddenFromAddressListsEnabled properties, then tests each user to see if they are hidden from the Address Book. The results are exported to an Excel file.
24+
25+
.EXAMPLE
26+
Get-MgUser -All -Property DisplayName, HiddenFromAddressListsEnabled | Select-Object DisplayName, HiddenFromAddressListsEnabled | Test-365ACAddressBook -HtmlFilePath "C:\Reports\AddressBookReport.html"
27+
This example pipes a list of users directly into Test-365ACAddressBook, which then checks if each user is hidden from the Address Book. The results are exported to an HTML file.
28+
29+
.NOTES
30+
This function requires the Microsoft Graph PowerShell SDK to retrieve user information from Microsoft 365.
31+
32+
.LINK
33+
https://docs.microsoft.com/powershell/module/microsoft.graph.users/get-mguser
34+
#>
35+
Function Test-365ACAddressBook {
36+
[CmdletBinding()]
37+
param
38+
(
39+
[Parameter(ValueFromPipeline = $true)]
40+
[array]$Users = (Get-MgUser -All -Property DisplayName, HiddenFromAddressListsEnabled | Select-Object DisplayName, HiddenFromAddressListsEnabled),
41+
42+
[ValidatePattern('\.xlsx$')]
43+
[string]$OutputExcelFilePath,
44+
45+
[ValidatePattern('\.html$')]
46+
[string]$HtmlFilePath,
47+
48+
[string]$TestedProperty = 'HiddenFromAddressBook'
49+
)
50+
BEGIN {
51+
$results = @()
52+
}
53+
PROCESS {
54+
foreach ($user in $Users) {
55+
$isHiddenFromAddressBook = [bool]($user.HiddenFromAddressListsEnabled)
56+
$result = [PSCustomObject]@{
57+
'User Display Name' = $user.DisplayName
58+
$TestedProperty = $isHiddenFromAddressBook
59+
}
60+
$results += $result
61+
}
62+
}
63+
END {
64+
$totalTests = $results.Count
65+
$passedTests = ($results | Where-Object { $_.$TestedProperty }).Count
66+
$failedTests = $totalTests - $passedTests
67+
if ($OutputExcelFilePath) {
68+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
69+
}
70+
elseif ($HtmlFilePath) {
71+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
72+
}
73+
else {
74+
Write-Output $results
75+
}
76+
}
77+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<#
2+
.SYNOPSIS
3+
Tests if users have a city property and generates test results.
4+
5+
.DESCRIPTION
6+
The Test-365ACCity function tests if users have a city property and generates test results. It takes an array of users as input and checks if each user has a city property. The test results are stored in an array of custom objects, which include the user's display name and the result of the test.
7+
8+
.PARAMETER Users
9+
Specifies the array of users to test. Each user should have a DisplayName and City property.
10+
11+
.PARAMETER OutputExcelFilePath
12+
Specifies the path to the output Excel file. If provided, the test results will be exported to an Excel file.
13+
14+
.PARAMETER HtmlFilePath
15+
Specifies the path to the output HTML file. If provided, the test results will be exported to an HTML file.
16+
17+
.PARAMETER TestedProperty
18+
Specifies the name of the tested property. Default value is 'Has City'.
19+
20+
.INPUTS
21+
An array of users with DisplayName and City properties.
22+
23+
.OUTPUTS
24+
If OutputExcelFilePath or HtmlFilePath is not provided, the function outputs an array of custom objects with the user's display name and the result of the test.
25+
26+
.EXAMPLE
27+
$users = Get-MgUser -All -Property DisplayName, City | Select-Object DisplayName, City
28+
Test-365ACCity -Users $users -OutputExcelFilePath 'C:\TestResults.xlsx'
29+
30+
This example tests if the users have a city property and exports the test results to an Excel file.
31+
32+
#>
33+
Function Test-365ACCity {
34+
[CmdletBinding()]
35+
param
36+
(
37+
[Parameter(ValueFromPipeline = $true)]
38+
[array]$Users = (Get-MgUser -All -Property DisplayName, City | Select-Object DisplayName, City),
39+
40+
[ValidatePattern('\.xlsx$')]
41+
[string]$OutputExcelFilePath,
42+
43+
[ValidatePattern('\.html$')]
44+
[string]$HtmlFilePath,
45+
46+
[string]$TestedProperty = 'Has City'
47+
)
48+
BEGIN {
49+
$results = @()
50+
}
51+
PROCESS {
52+
foreach ($user in $Users) {
53+
$hasCity = [bool]($user.City)
54+
$result = [PSCustomObject]@{
55+
'User Display Name' = $user.DisplayName
56+
$TestedProperty = $hasCity
57+
}
58+
$results += $result
59+
}
60+
}
61+
END {
62+
$totalTests = $results.Count
63+
$passedTests = ($results | Where-Object { $_.$TestedProperty }).Count
64+
$failedTests = $totalTests - $passedTests
65+
if ($OutputExcelFilePath) {
66+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
67+
}
68+
elseif ($HtmlFilePath) {
69+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
70+
}
71+
else {
72+
Write-Output $results
73+
}
74+
}
75+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<#
2+
.SYNOPSIS
3+
Tests whether users in Microsoft 365 have a country assigned and optionally validates against a list of valid countries.
4+
.DESCRIPTION
5+
The Test-365ACCountry function checks if users in Microsoft 365 have a country assigned to their profile. It can also validate these countries against a provided list of valid countries. The results of this test can be exported to an Excel file, an HTML file, or displayed in the console.
6+
.PARAMETER Users
7+
Specifies the users to be tested. If not specified, the function will test all users in the organization by retrieving their DisplayName and Country properties.
8+
.PARAMETER ValidationExcelFilePath
9+
Specifies the path to an Excel file containing a list of valid countries. If specified, the function will validate the countries of the users against this list.
10+
.PARAMETER OutputExcelFilePath
11+
Specifies the path to save the test results as an Excel file. If not specified, the test results will be displayed in the console. The path must end with '.xlsx'.
12+
.PARAMETER HtmlFilePath
13+
Specifies the path to save the test results as an HTML file. If not specified, the test results will be displayed in the console. The path must end with '.html'.
14+
.PARAMETER TestedProperty
15+
Specifies the name of the tested property. This will be used as the column name in the test results. Defaults to 'Has Country' but changes to 'Has Valid Country' if a validation list is provided.
16+
.EXAMPLE
17+
Test-365ACCountry -Users (Get-MgUser -All) -ValidationExcelFilePath "C:\Validation.xlsx" -OutputExcelFilePath "C:\Results.xlsx"
18+
Tests all users in the organization, validates their countries against the list of valid countries in "Validation.xlsx", and saves the test results to "Results.xlsx".
19+
.EXAMPLE
20+
Test-365ACCountry -Users (Get-MgUser -All) -HtmlFilePath "C:\Results.html"
21+
Tests all users in the organization and saves the test results as an HTML file named "Results.html".
22+
.NOTES
23+
Requires the ImportExcel module for exporting results to Excel. If not installed, an error will be displayed.
24+
The Export-365ACResultToExcel and Export-365ACResultToHtml functions must be defined for exporting results to Excel or HTML, respectively.
25+
.LINK
26+
https://github.com/DevClate/365AutomatedCheck
27+
#>
28+
Function Test-365ACCountry {
29+
[CmdletBinding()]
30+
param
31+
(
32+
[Parameter(ValueFromPipeline = $true)]
33+
[array]$Users = (Get-MgUser -All -Property DisplayName, Country | Select-Object DisplayName, Country),
34+
35+
[ValidatePattern('\.xlsx$')]
36+
[string]$ValidationExcelFilePath,
37+
38+
[ValidatePattern('\.xlsx$')]
39+
[string]$OutputExcelFilePath,
40+
41+
[ValidatePattern('\.html$')]
42+
[string]$HtmlFilePath,
43+
[string]$TestedProperty = 'Has Country'
44+
)
45+
BEGIN {
46+
47+
$validCountries = @()
48+
if ($ValidationExcelFilePath) {
49+
if (!(Get-Command Import-Excel -ErrorAction SilentlyContinue)) {
50+
Stop-PSFFunction -Message "Import-Excel cmdlet not found. Please install the ImportExcel module." -ErrorRecord $_ -Tag 'MissingModule'
51+
return@
52+
}
53+
# Import the Excel file to get valid countries
54+
$validCountries = Import-Excel -Path $ValidationExcelFilePath | Select-Object -ExpandProperty Country -Unique
55+
}
56+
$results = @()
57+
}
58+
PROCESS {
59+
$columnName = $ValidationExcelFilePath ? 'Has Valid Country' : 'Has Country'
60+
foreach ($user in $Users) {
61+
$hasCountry = [bool]($user.Country)
62+
if ($ValidationExcelFilePath) {
63+
$hasCountry = $user.Country -in $validCountries
64+
}
65+
$result = [PSCustomObject]@{
66+
'User Display Name' = $user.DisplayName
67+
$columnName = $hasCountry
68+
}
69+
$results += $result
70+
}
71+
}
72+
END {
73+
$totalTests = $results.Count
74+
$passedTests = ($results | Where-Object { $_.$columnName }).Count
75+
$failedTests = $totalTests - $passedTests
76+
if ($OutputExcelFilePath) {
77+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
78+
}
79+
elseif ($HtmlFilePath) {
80+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
81+
}
82+
else {
83+
Write-PSFMessage -Level Output -Message ($results | Out-String)
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)