Skip to content

Commit 8d4010e

Browse files
committed
Update module version to 0.0.3 and rename Set-365ACDefaultPath to Set-365ACDefaultOutputPath and updated Excel Validation for functions
1 parent 5566bae commit 8d4010e

10 files changed

Lines changed: 137 additions & 116 deletions

365AutomatedCheck.psd1

Lines changed: 2 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.2'
15+
ModuleVersion = '0.0.3'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
@@ -89,7 +89,7 @@ FunctionsToExport = @(
8989
'Test-365ACJobTitle',
9090
'Convert-365ACXmlToHtml',
9191
'Get-365ACPesterConfiguration',
92-
'Set-365ACDefaultPath'
92+
'Set-365ACDefaultOutputPath'
9393
)
9494

9595
# 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.

functions/private/Export-365ACResultToExcel.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
function Export-365ACResultToExcel {
22
param (
33
[array]$Results,
4-
[string]$ExcelFilePath,
4+
[string]$OutputExcelFilePath,
55
[int]$TotalTests,
66
[int]$PassedTests,
77
[int]$FailedTests,
88
[string]$TestedProperty
99
)
1010

11-
$results | Export-Excel -Path $ExcelFilePath -WorkSheetname 'Results' -AutoSize -FreezePane 7, 1 -NoHeader -StartRow 7 -ConditionalText (New-ConditionalText -Text 'Yes' -BackgroundColor Green -ForegroundColor White), (New-ConditionalText -Text 'No' -BackgroundColor Red -ForegroundColor White)
11+
$results | Export-Excel -Path $OutputExcelFilePath -WorkSheetname 'Results' -AutoSize -FreezePane 7, 1 -NoHeader -StartRow 7 -ConditionalText (New-ConditionalText -Text 'Yes' -BackgroundColor Green -ForegroundColor White), (New-ConditionalText -Text 'No' -BackgroundColor Red -ForegroundColor White)
1212

13-
$excelPackage = Open-ExcelPackage -Path $ExcelFilePath
13+
$excelPackage = Open-ExcelPackage -Path $OutputExcelFilePath
1414
$resultSheet = $excelPackage.Workbook.Worksheets['Results']
1515

1616
# Adding title to the Results Sheet

functions/private/Set-365ACDefaultPath.ps1 renamed to functions/private/Set-365ACDefaultOutputPath.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
function Set-365ACDefaultPath {
1+
function Set-365ACDefaultOutputPath {
22
param (
33
[string] $Path,
44
[string] $DefaultPath
55
)
66
if (-not $Path) {
7-
$todaysDate = (Get-Date).ToString("yyyyMMdd")
7+
# today's date and time in the format yyyyMMdd hhmmss
8+
$todaysDate = (Get-Date).ToString("yyyyMMdd-HHmm")
89
$Path = Join-Path -Path (Get-Location) -ChildPath "365ACReports/$todaysDate-$DefaultPath"
910
$folderPath = [System.IO.Path]::GetDirectoryName($Path)
1011

functions/public/Invoke-365AutomatedCheck.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function Invoke-365AutomatedCheck {
6363

6464
#Requires -Module Pester, ImportExcel
6565

66-
$XmlPath = Set-365ACDefaultPath -Path $XmlPath -DefaultPath '365ACReport.xml'
66+
$XmlPath = Set-365ACDefaultOutputPath -Path $XmlPath -DefaultPath '365ACReport.xml'
6767
Write-Host "Using XML Path: $XmlPath"
6868

69-
$OutputHtmlPath = Set-365ACDefaultPath -Path $OutputHtmlPath -DefaultPath '365ACReport.html'
69+
$OutputHtmlPath = Set-365ACDefaultOutputPath -Path $OutputHtmlPath -DefaultPath '365ACReport.html'
7070
Write-Host "Using HTML Output Path: $OutputHtmlPath"
7171

7272
$pesterConfig = Get-365ACPesterConfiguration -Path $Path -Tag $Tag -ExcludeTag $ExcludeTag -XmlPath $XmlPath -PesterConfiguration $PesterConfiguration -Verbosity $Verbosity -PassThru $PassThru

functions/public/Test-365ACCompanyName.ps1

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,57 @@
1-
<#
2-
.SYNOPSIS
3-
This function tests whether users have a company name associated with their account and exports the results to Excel, HTML, or the console. .DESCRIPTION
4-
The Test-365ACCompanyName function checks whether users have a company name associated with their account. It takes an array of users, an optional Excel file path as input. It then iterates through each user, determines if they have a company name, and generates a result object for each user. The function returns the results as an array of objects or exports them to an Excel file or an HTML file.
5-
6-
.PARAMETER Users
7-
Specifies an array of users to test. Each user should have a display name and a company name property.
8-
9-
.PARAMETER ExcelFilePath
10-
Specifies the file path to export the results to an Excel file. If this parameter is provided, the Export-Excel module must be installed.
11-
12-
.PARAMETER HtmlFilePath
13-
Specifies the file path to export the results to an HTML file.
14-
15-
.PARAMETER TestedProperty
16-
Specifies the property that is being tested. Default is 'Has Company Name'.
17-
18-
.EXAMPLE
19-
Test-365ACCompanyName -Users $users -ExcelFilePath "C:\Results.xlsx"
20-
This example tests the company names of the users in the $users array and exports the results to an Excel file located at "C:\Results.xlsx".
21-
22-
.EXAMPLE
23-
Test-365ACCompanyName -Users $users -HtmlFilePath "C:\Results.html"
24-
This example tests the company names of the users in the $users array and exports the results to an HTML file located at "C:\Results.html".
25-
26-
.NOTES
27-
- This function requires the ImportExcel module to export results to Excel. If the module is not installed, an error will be displayed.
28-
- The Export-365ACResultToExcel and Export-365ACResultToHtml functions are assumed to be defined elsewhere in the script.
29-
30-
.LINK
31-
https://github.com/DevClate/365AutomatedCheck
32-
#>
331
Function Test-365ACCompanyName {
342
[CmdletBinding()]
353
param
364
(
375
[Parameter(ValueFromPipeline = $true)]
38-
[array]$Users = (get-mguser -all -Property DisplayName, CompanyName | Select-Object displayname, CompanyName),
6+
[array]$Users = (get-mguser -all -Property DisplayName, CompanyName | Select-Object DisplayName, CompanyName),
7+
8+
[ValidatePattern('\.xlsx$')]
9+
[string]$ValidationExcelFilePath,
3910

4011
[ValidatePattern('\.xlsx$')]
41-
[string]$ExcelFilePath,
12+
[string]$OutputExcelFilePath,
4213

4314
[ValidatePattern('\.html$')]
4415
[string]$HtmlFilePath,
4516

4617
[string]$TestedProperty = 'Has Company Name'
4718
)
4819
BEGIN {
49-
if ($ExcelFilePath -and !(Get-Command Export-Excel -ErrorAction SilentlyContinue)) {
50-
Write-Error "Export-Excel cmdlet not found. Please install the ImportExcel module."
51-
return
20+
$validCompanyNames = @()
21+
if ($ValidationExcelFilePath) {
22+
if (!(Get-Command Import-Excel -ErrorAction SilentlyContinue)) {
23+
Write-Error "Import-Excel cmdlet not found. Please install the ImportExcel module."
24+
return@
25+
}
26+
# Import the Excel file to get valid company names
27+
$validCompanyNames = Import-Excel -Path $ValidationExcelFilePath | Select-Object -ExpandProperty CompanyName -Unique
5228
}
5329
$results = @()
5430
}
5531
PROCESS {
32+
$columnName = $ValidationExcelFilePath ? 'Has Valid Company Name' : 'Has Company Name'
5633
foreach ($user in $Users) {
5734
$hasCompanyName = [bool]($user.CompanyName)
35+
if ($ValidationExcelFilePath) {
36+
$hasCompanyName = $user.CompanyName -in $validCompanyNames
37+
}
5838
$result = [PSCustomObject]@{
5939
'User Display Name' = $user.DisplayName
60-
'Has Company Name' = $hasCompanyName
40+
$columnName = $hasCompanyName
6141
}
6242
$results += $result
6343
}
6444
}
6545
END {
6646
$totalTests = $results.Count
67-
$passedTests = ($results | Where-Object { $_.'Has Company Name' }).Count
47+
# Update passed and failed tests calculation based on the new logic
48+
$passedTests = ($results | Where-Object { $_.$columnName }).Count
6849
$failedTests = $totalTests - $passedTests
69-
if ($ExcelFilePath) {
70-
Export-365ACResultToExcel -Results $results -ExcelFilePath $ExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
50+
if ($OutputExcelFilePath) {
51+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7152
}
7253
elseif ($HtmlFilePath) {
73-
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
54+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7455
}
7556
else {
7657
Write-Output $results

functions/public/Test-365ACDepartment.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.PARAMETER Users
99
Specifies the array of users to be tested. The users should have the 'DisplayName' and 'Department' properties.
1010
11-
.PARAMETER ExcelFilePath
11+
.PARAMETER OutputExcelFilePath
1212
Specifies the path to the Excel file where the test results will be exported. If this parameter is specified, the function will use the Export-365ACResultToExcel function to export the results to an Excel file.
1313
1414
.PARAMETER HtmlFilePath
@@ -18,7 +18,7 @@
1818
Specifies the property that is being tested. Default is 'Has Department'.
1919
2020
.EXAMPLE
21-
Test-365ACDepartment -Users $users -ExcelFilePath "C:\TestResults.xlsx"
21+
Test-365ACDepartment -Users $users -OutputExcelFilePath "C:\TestResults.xlsx"
2222
Tests the department property of the specified users and exports the test results to an Excel file.
2323
2424
.EXAMPLE
@@ -37,43 +37,53 @@ Function Test-365ACDepartment {
3737
param
3838
(
3939
[Parameter(ValueFromPipeline = $true)]
40-
[array]$Users = (get-mguser -all -Property DisplayName, Department | Select-Object displayname, Department),
40+
[array]$Users = (get-mguser -all -Property DisplayName, Department | Select-Object DisplayName, Department),
4141

4242
[ValidatePattern('\.xlsx$')]
43-
[string]$ExcelFilePath,
43+
[string]$ValidationExcelFilePath,
44+
45+
[ValidatePattern('\.xlsx$')]
46+
[string]$OutputExcelFilePath,
4447

4548
[ValidatePattern('\.html$')]
4649
[string]$HtmlFilePath,
47-
4850
[string]$TestedProperty = 'Has Department'
4951
)
5052
BEGIN {
51-
if ($ExcelFilePath -and !(Get-Command Export-Excel -ErrorAction SilentlyContinue)) {
52-
Write-Error "Export-Excel cmdlet not found. Please install the ImportExcel module."
53-
return
53+
$validDepartments = @()
54+
if ($ValidationExcelFilePath) {
55+
if (!(Get-Command Import-Excel -ErrorAction SilentlyContinue)) {
56+
Write-Error "Import-Excel cmdlet not found. Please install the ImportExcel module."
57+
return
58+
}
59+
# Import the Excel file to get valid department names
60+
$validDepartments = Import-Excel -Path $ValidationExcelFilePath | Select-Object -ExpandProperty Department -Unique
5461
}
5562
$results = @()
5663
}
5764
PROCESS {
65+
$columnName = $ValidationExcelFilePath ? 'Has Valid Department' : 'Has Department'
5866
foreach ($user in $Users) {
59-
#Write-Output "Checking user $($user.DisplayName) with department $($user.Department)"
6067
$hasDepartment = [bool]($user.Department)
68+
if ($ValidationExcelFilePath) {
69+
$hasDepartment = $user.Department -in $validDepartments
70+
}
6171
$result = [PSCustomObject]@{
6272
'User Display Name' = $user.DisplayName
63-
'Has Department' = $hasDepartment
73+
$columnName = $hasDepartment
6474
}
6575
$results += $result
6676
}
6777
}
6878
END {
6979
$totalTests = $results.Count
70-
$passedTests = ($results | Where-Object { $_.'Has Department' }).Count
80+
$passedTests = ($results | Where-Object { $_.$columnName }).Count
7181
$failedTests = $totalTests - $passedTests
72-
if ($ExcelFilePath) {
73-
Export-365ACResultToExcel -Results $results -ExcelFilePath $ExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
82+
if ($OutputExcelFilePath) {
83+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7484
}
7585
elseif ($HtmlFilePath) {
76-
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
86+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7787
}
7888
else {
7989
Write-Output $results

functions/public/Test-365ACFaxNumber.ps1

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
.PARAMETER Users
99
Specifies the array of users to test. If not provided, it retrieves all users using the Get-MgUser cmdlet.
1010
11-
.PARAMETER ExcelFilePath
11+
.PARAMETER OutputExcelFilePath
1212
Specifies the path to export the results as an Excel file. If this parameter is provided, the Export-365ACResultToExcel function is called to export the results.
1313
1414
.PARAMETER HtmlFilePath
@@ -18,7 +18,7 @@
1818
Specifies the property that is being tested. Default is 'Has Fax Number'.
1919
2020
.EXAMPLE
21-
Test-365ACFaxNumber -Users $users -ExcelFilePath "C:\Results.xlsx"
21+
Test-365ACFaxNumber -Users $users -OutputExcelFilePath "C:\Results.xlsx"
2222
Tests the specified users for fax numbers and exports the results to an Excel file.
2323
2424
.EXAMPLE
@@ -38,42 +38,54 @@ Function Test-365ACFaxNumber {
3838
param
3939
(
4040
[Parameter(ValueFromPipeline = $true)]
41-
[array]$Users = (get-mguser -all -Property DisplayName, FaxNumber | Select-Object displayname, FaxNumber),
41+
[array]$Users = (get-mguser -all -Property DisplayName, FaxNumber | Select-Object DisplayName, FaxNumber),
4242

4343
[ValidatePattern('\.xlsx$')]
44-
[string]$ExcelFilePath,
45-
44+
[string]$ValidationExcelFilePath,
45+
46+
[ValidatePattern('\.xlsx$')]
47+
[string]$OutputExcelFilePath,
48+
4649
[ValidatePattern('\.html$')]
4750
[string]$HtmlFilePath,
48-
51+
4952
[string]$TestedProperty = 'Has Fax Number'
5053
)
5154
BEGIN {
52-
if ($ExcelFilePath -and !(Get-Command Export-Excel -ErrorAction SilentlyContinue)) {
53-
Write-Error "Export-Excel cmdlet not found. Please install the ImportExcel module."
54-
return
55+
$validFaxNumbers = @()
56+
if ($ValidationExcelFilePath) {
57+
if (!(Get-Command Import-Excel -ErrorAction SilentlyContinue)) {
58+
Write-Error "Import-Excel cmdlet not found. Please install the ImportExcel module."
59+
return
60+
}
61+
# Import the Excel file to get valid fax numbers
62+
$validFaxNumbers = Import-Excel -Path $ValidationExcelFilePath | Select-Object -ExpandProperty FaxNumber -Unique
5563
}
5664
$results = @()
5765
}
5866
PROCESS {
67+
$columnName = $ValidationExcelFilePath ? 'Has Valid Fax Number' : 'Has Fax Number'
5968
foreach ($user in $Users) {
6069
$hasFaxNumber = [bool]($user.FaxNumber)
70+
if ($ValidationExcelFilePath) {
71+
$hasFaxNumber = $user.FaxNumber -in $validFaxNumbers
72+
}
6173
$result = [PSCustomObject]@{
6274
'User Display Name' = $user.DisplayName
63-
'Has Fax Number' = $hasFaxNumber
75+
$columnName = $hasFaxNumber
6476
}
6577
$results += $result
6678
}
6779
}
6880
END {
6981
$totalTests = $results.Count
70-
$passedTests = ($results | Where-Object { $_.'Has Fax Number' }).Count
82+
$passedTests = ($results | Where-Object { $_.$columnName }).Count
7183
$failedTests = $totalTests - $passedTests
72-
if ($ExcelFilePath) {
73-
Export-365ACResultToExcel -Results $results -ExcelFilePath $ExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
84+
if ($OutputExcelFilePath) {
85+
Export-365ACResultToExcel -Results $results -OutputExcelFilePath $OutputExcelFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7486
}
7587
elseif ($HtmlFilePath) {
76-
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $TestedProperty
88+
Export-365ACResultToHtml -Results $results -HtmlFilePath $HtmlFilePath -TotalTests $totalTests -PassedTests $passedTests -FailedTests $failedTests -TestedProperty $columnName
7789
}
7890
else {
7991
Write-Output $results

0 commit comments

Comments
 (0)