Created
August 28, 2018 20:10
-
-
Save webtroter/d44a5725849ad4cd30bbadd1efb69bd2 to your computer and use it in GitHub Desktop.
PSSA Weird error. #1060
This file contains hidden or 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
enum Departments { | |
Admin | |
Compta | |
Ventes | |
RetDev | |
DevLogiciel | |
DevMicro | |
DevMateriel | |
Operations | |
Production | |
Support | |
Informatique | |
Tests | |
} | |
$Departments = @( | |
"Administration", | |
"Comptabilité", | |
"Ventes", | |
"Recherche et Développement", | |
"Développement Logiciel", | |
"Développement Micrologiciel", | |
"Développement Matériel", | |
"Opérations", | |
"Production", | |
"Service à la clientèle", | |
"Informatique", | |
"QATests" | |
) | |
class Contact { | |
# Optionally, add attributes to prevent invalid values | |
[ValidateNotNullOrEmpty()][string]$Nom | |
[ValidateNotNullOrEmpty()][string]$Prenom | |
[string[]]$TitrePro | |
[string]$DisplayName | |
[ValidateNotNullOrEmpty()][string]$Username | |
[string]$Extension | |
[ValidateNotNullOrEmpty()][string]$TitreFR | |
[ValidateNotNullOrEmpty()][string]$TitreEN | |
[string]$Titre | |
[Departments]$Department | |
[string]$MobilePhone | |
[string]$UPN | |
[string]$Email | |
[ValidateNotNullOrEmpty()][Company]$Company | |
#Method to generate DisplayName | |
hidden SetDisplayName([string]$Nom, [string]$Prenom, [string[]]$TitrePro) { | |
$this.DisplayName = $Prenom + ' ' + $Nom | |
if ($TitrePro) { | |
foreach ($item in $TitrePro) { | |
$this.DisplayName += ', ' + $item.Trim() | |
} | |
} | |
} | |
hidden SetDisplayName() { | |
$this.DisplayName = $this.Prenom + ' ' + $this.Nom | |
if ($this.TitrePro) { | |
foreach ($item in $this.TitrePro) { | |
$this.DisplayName += ', ' + $item.Trim() | |
} | |
} | |
} | |
#Method to generate Username | |
hidden SetUsername($Username) { | |
if ($Username) { | |
$this.Username = $Username | |
} | |
} | |
hidden SetUsername() { | |
$this.Username = ([Text.Encoding]::ASCII.GetString( | |
[Text.Encoding]::GetEncoding("Cyrillic").GetBytes( | |
$this.Prenom.Split("-, ")[0][0] + (& {If ($this.Prenom.Split("-, ")[1]) {$this.Prenom.Split("-, ")[1][0]}}) + $this.Nom.Split(' ')[0] | |
)).ToLowerInvariant()) | |
} | |
#Method to get the department string | |
[string] GetDepartment() { | |
return $Script:Departments[[int]$this.Department] | |
} | |
SetDepartment() { | |
$this.Department = (Read-Host -Prompt "`nChoisir parmis les suivants:`n$([Departments]::getvalues([Departments])) `nDépartement de l'utilisateur") | |
} | |
SetDepartment([Departments]$Department) { | |
if ($Department) { | |
$this.Department = $Department | |
} | |
} | |
#Constructor helper | |
# Base | |
hidden init([string]$Nom, [string]$Prenom, [string]$TitreFR, [string]$TitreEN, [Company]$Company) { | |
$this.init($Nom, $Prenom, $null, $TitreFR, $TitreEN, $Company) | |
} | |
# Base + TitreProfessionnel | |
hidden init([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $null, $Company) | |
} | |
# Base + TitreProfessionnel + NuméroMobile | |
hidden init([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $MobilePhone, $null, $Company) | |
} | |
# Base + TitreProfessionnel + NuméroMobile + ExtensionTéléphonique | |
hidden init([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [string]$Extension, [Company]$Company) { | |
$this.Company = $Company | |
$this.Nom = $Nom | |
$this.Prenom = $Prenom | |
$this.TitrePro = foreach ($item in $TitrePro) { | |
$item.Trim() | |
} | |
$this.SetDisplayName( $Nom, $Prenom, $TitrePro) | |
$this.SetUsername() | |
$this.Extension = $Extension | |
$this.TitreFR = $TitreFR | |
$this.TitreEN = $TitreEN | |
$this.Titre = $this.TitreFR + " | " + $this.TitreEN | |
$this.MobilePhone = $MobilePhone | |
$this.UPN = $this.Username + '@' + $this.Company.WebSite | |
$this.Email = $this.Username + '@' + $this.Company.WebSite | |
} | |
# Base + TitreProfessionnel + NuméroMobile + ExtensionTéléphonique + Departement | |
hidden init([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [string]$Extension, [Departments]$Department, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $MobilePhone, $Extension, $Company) | |
$this.SetDepartment($Department) | |
} | |
hidden init($MSOLUser) { | |
$this.init( | |
$MSOLUser.LastName, | |
$MSOLUser.FirstName, | |
#Takes the display name and extracts TitrePro, if there is one or more. | |
(& {If ($MSOLUser.DisplayName.Split(',')[1]) {$MSOLUser.DisplayName.Split(',')[1..$MSOLUser.DisplayName.Split(',').Length].Split(',').Trim()}}), | |
# Splits the title and extract both languages Titles | |
$MSOLUser.Title.Split('|', [System.StringSplitOptions]::RemoveEmptyEntries)[0].Trim(), | |
$MSOLUser.Title.Split('|', [System.StringSplitOptions]::RemoveEmptyEntries)[1].Trim(), | |
$MSOLUser.MobilePhone, | |
# Splits the Office Phone to extract the extension, if there is one. | |
(& {If ($MSOLUser.PhoneNumber.Split('#')[1]) {$MSOLUser.PhoneNumber.Split('#')[1]}}), | |
# Converts the dept to [Departments] | |
(& {If ($Script:Departments.IndexOf($MSOLUser.Department) -ne -1) {[Departments]$Script:Departments.IndexOf($MSOLUser.Department)} else {[Departments]::Tests}}), | |
[Company]::New("Astus", $MSOLUser.StreetAddress, $MSOLUser.City, $MSOLUser.State, $MSOLUser.Country, $MSOLUser.PostalCode, $MSOLUser.PhoneNumber.Split('#')[0].Trim(), $MSOLUser.Fax, $null, $MSOLUser.UserPrincipalName.Split('@')[1]) | |
) | |
} | |
#Unused constructor | |
<# | |
Contact([hashtable]$Import, [Company]$Company) { | |
$this.Company = $Company | |
$this.Nom = $Import.Nom | |
$this.Prenom = $Import.Prenom | |
$this.DisplayName = $Import.DisplayName | |
$this.Username = Remove-StringDiacritic ($this.Prenom[0] + $this.Nom).ToLowerInvariant() | |
$this.Extension = $Import.Extension | |
$this.TitreFR = $Import.TitreFR | |
$this.TitreEN = $Import.TitreEN | |
$this.Titre = $this.TitreFR + " | " + $this.TitreEN | |
$this.Department = $Import.Dept | |
$this.MobilePhone = $Import.MobilePhone | |
$this.UPN = $this.Username + '@' + $this.Company.WebSite | |
$this.Email = $this.Username + '@' + $this.Company.WebSite | |
}#> | |
# Constructeur utilisant les chained helper method. | |
Contact([string]$Nom, [string]$Prenom, [string]$TitreFR, [string]$TitreEN, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitreFR, $TitreEN, $Company) | |
} | |
Contact([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $Company) | |
} | |
Contact([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $MobilePhone, $Company) | |
} | |
Contact([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [string]$Extension, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $MobilePhone, $Extension, $Company) | |
} | |
Contact([string]$Nom, [string]$Prenom, [string[]]$TitrePro, [string]$TitreFR, [string]$TitreEN, [string]$MobilePhone, [string]$Extension, [Departments]$Department, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitrePro, $TitreFR, $TitreEN, $MobilePhone, $Extension, $Department, $Company) | |
} | |
#Constructor with username specified | |
Contact($Nom, $Prenom, $Username, $TitreFR, $TitreEN, $MobilePhone, $Extension, $Department, [Company]$Company) { | |
$this.init($Nom, $Prenom, $TitreFR, $TitreEN, $MobilePhone, $Extension, $Department, $Company) | |
$this.SetUsername($Username) | |
} | |
# "Empty" Constructor | |
Contact([Company]$Company) { | |
$this.init("Test", "User", "Testeur", "Tester", $Company) | |
$this.SetDepartment([Departments]::Tests) | |
} # ($Nom, $Prenom, $TitreFR, $TitreEN, $Company) | |
Contact([Microsoft.Online.Administration.User]$MSOLUser) { | |
$this.init($MSOLUser) | |
} | |
#Override ToString | |
[String] ToString() { | |
return $this.DisplayName | |
} | |
} | |
class Company { | |
[ValidateNotNullOrEmpty()][string]$CompanyName | |
#Todo Departements | |
[ValidateNotNullOrEmpty()][string]$StreetAddress | |
[ValidateNotNullOrEmpty()][string]$City | |
[ValidateNotNullOrEmpty()][string]$State | |
[ValidateNotNullOrEmpty()][string]$Country | |
[ValidateNotNullOrEmpty()][string]$PostalCode | |
[ValidateNotNullOrEmpty()][string]$OfficePhone | |
[ValidateNotNullOrEmpty()][string]$FaxNumber | |
[string]$TollFree | |
[ValidateNotNullOrEmpty()][string]$WebSite | |
[String] ToString() { | |
return $this.CompanyName | |
} | |
Company( | |
[string]$CompanyName, | |
[string]$StreetAddress, | |
[string]$City, | |
[string]$State, | |
[string]$Country, | |
[string]$PostalCode, | |
[string]$OfficePhone, | |
[string]$FaxNumber, | |
[string]$TollFree, | |
[string]$WebSite) | |
{ | |
$this.CompanyName = $CompanyName | |
$this.StreetAddress = $StreetAddress | |
$this.City = $City | |
$this.State = $State | |
$this.Country = $Country | |
$this.PostalCode = $PostalCode | |
$this.OfficePhone = $OfficePhone | |
$this.FaxNumber = $FaxNumber | |
$this.TollFree = $TollFree | |
$this.WebSite = $WebSite | |
} | |
Company() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment