Last active
February 11, 2018 06:58
-
-
Save mattmcnabb/ece527628bfe407a407765c6ded8ae4b to your computer and use it in GitHub Desktop.
Line-Of-BusinessTesting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-ADStaffAttributes { | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory = $true)] | |
[Microsoft.ActiveDirectory.Management.ADUser] | |
$Identity, | |
[switch] | |
$Quiet | |
) | |
if ($Quiet) | |
{ | |
$Splat = @{ | |
Script = @{ | |
Path = "$PSScriptRoot/Test-ADStaffAttributes.tests.ps1" | |
Parameters = @{Identity = $Identity} | |
} | |
Show = "None" | |
PassThru = $true | |
} | |
$Result = Invoke-Pester @Splat | |
if ($Result.FailedCount) {$false} else {$true} | |
} | |
else | |
{ | |
$Splat = @{ | |
Script = @{ | |
Path = "$PSScriptRoot/Test-ADStaffAttributes.tests.ps1" | |
Parameters = @{ | |
Identity = $Identity | |
} | |
} | |
} | |
Invoke-Pester @Splat | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param | |
( | |
[Microsoft.ActiveDirectory.Management.ADUser] | |
$Identity | |
) | |
Pester\Describe "AD User attributes: [$($Identity.Name)]" { | |
BeforeAll { | |
$Attributes = "DisplayName","Title","Mail","SamAccountName","GivenName","Surname","EmployeeID","Company","ProxyAddresses" | |
$PrimarySMTPDomain = "company.com" | |
$SecondarySMTPDomain = "company.com" | |
$Identity = Get-ADUser -Identity $Identity -Properties $Attributes | |
} | |
Context "EmployeeID" { | |
Pester\It "EmployeeID is not null" { | |
$Identity.EmployeeID | Should Not Be NullOrEmpty | |
} | |
} | |
Pester\Context "Title" { | |
Pester\It "Title is not null" { | |
$Identity.Title | Should Not Be NullOrEmpty | |
} | |
} | |
Pester\Context "Email" { | |
Pester\It "email is not null" { | |
$Identity.Mail | Should Not Be NullOrEmpty | |
} | |
Pester\It "email domain name" { | |
$Identity.Mail -replace "^.+@" | Should Be $PrimarySMTPDomain | |
} | |
Pester\It "email is lowercase" { | |
$Identity.Mail | Should BeExactly $Identity.Mail.tolower() | |
} | |
} | |
Pester\Context "UPN" { | |
Pester\It "UPN is lowercase" { | |
$Identity.UserPrincipalName | Should BeExactly $Identity.UserPrincipalName.ToLower() | |
} | |
Pester\It "UPN domain name" { | |
$Identity.UserPrincipalName -replace "^.+@" | Should Be $PrimarySMTPDomain | |
} | |
} | |
Pester\Context "ProxyAddresses" { | |
BeforeAll { | |
$Proxies = $Identity.ProxyAddresses | |
$Primaries = $Proxies | Where-Object {$_ -cmatch "^SMTP:"} | |
$ProxiesNoPrefix = $Identity.ProxyAddresses -replace "SMTP:" | |
} | |
Pester\It "ProxyAddresses are prefixed" { | |
foreach ($Proxy in $Proxies) { | |
$Proxy | Should Match "^SMTP:" | |
} | |
} | |
Pester\It "ProxyAddresses are lower case" { | |
foreach ($Proxy in $ProxiesNoPrefix) { | |
$Proxy | Should BeExactly $Proxy.ToLower() | |
} | |
} | |
Pester\It "has exactly one Primary ProxyAddress" { | |
$Primaries.Count | Should Be 1 | |
} | |
Pester\It "Primary proxy matches primary domain" { | |
$Primaries | Should Match $PrimarySMTPDomain | |
} | |
Pester\It "Primary proxy matches Surname" { | |
$Primaries | Should Match "^SMTP:\w+\.$($Identity.Surname)@\w+\.\w+$" | |
} | |
} | |
Pester\Context "SamAccountName" { | |
Pester\It "SamAccountName is lowercase" { | |
$Identity.SamAccountName | Should BeExactly $Identity.SamAccountName.ToLower() | |
} | |
} | |
Pester\Context "Company" { | |
BeforeAll { | |
$BuildingCodes = "HQ","EU","AS","US" | |
} | |
Pester\It "Company is not null" { | |
$Identity.Company | Should Not Be NullOrEmpty | |
} | |
Pester\It "Company doesn't have preceding spaces" { | |
$Identity.Company | Should Not Match "^\s+" | |
} | |
Pester\It "Company doesn't have trailing spaces" { | |
$Identity.Company | Should Not Match "\s+$" | |
} | |
Pester\It "Company is single space delimited" { | |
$Identity.Company | Should Not Match '\s{2}' | |
} | |
Pester\It "Has valid company codes" { | |
$Company -cin $BuildingCodes | Should Be $true | |
} | |
} | |
Context "Spelling" { | |
Pester\It "UPN matches email" { | |
$Identity.UserPrincipalName | Should BeExactly $Identity.Mail | |
} | |
Pester\It "DisplayName matches spelling of GivenName" { | |
$Identity.DisplayName | Should Match "^$($Identity.GivenName)\s\w+" | |
} | |
Pester\It "DisplayName matches spelling of Surname" { | |
$Identity.DisplayName | Should Match "\w+\s$($Identity.Surname)$" | |
} | |
Pester\It "Mail matches Surname" { | |
$Identity.Mail | Should Match "^\w+\.$($Identity.Surname)@\w+\.\w+$" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ADUser -Filter * | Foreach-Object { | |
[PSCustomObject]@{ | |
Name = $_.Name | |
SamAccountName = $_.SamAccountName | |
InCompliance = Test-ADStaffAttributes -Identity $_ -Quiet | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment