diff --git a/Beispielprojekt/.gitkeep b/Beispielprojekt/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Beispielprojekt/Check-Invitations b/Beispielprojekt/Check-Invitations new file mode 100644 index 0000000000000000000000000000000000000000..6d529b3e855793935fe8f42fa8d4afa57ffa4337 --- /dev/null +++ b/Beispielprojekt/Check-Invitations @@ -0,0 +1,86 @@ +function Check-Invitations +{ + # Setzen der Parameter für die Funktionen + [CmdletBinding()] + param + ( + # Pfad zur Excel-Datei + $xlsxpath + ) + + # Importieren der Excel-Datei mit den Mailboxen + $File = Import-Excel -Path $xlsxpath + # Alt: $file = Import-CSV -Path "C:\Abschlussprojekt\Files\mai.rwth-aachen.de.csv" -Delimiter ";" + + # Importieren aller Mailboxen aus dem Mailsystem + $AllMbxsInMailsystem = $WS.GetMailboxList() | Select UPN,EMailaddress,GivenName,Sn,@{Name="QuotaInMB"; Expression = {$_.QuotaInB/1048576}},@{Name="TotalItemSizeInMB"; Expression = {$_.TotalItemsizeInB/1048576}},Mailboxtype + + # Importieren aller Invitations aus dem Mailsystem + $AllInvitations = $WS.GetInvitations() + + foreach($MbxinFile in $File) + { + if($MbxInFile.UPN -eq $null) + { + # Sucht nach dem jeweiligen Postfach im Mailsystem + $MbxInMailSystem = $AllMbxsInMailsystem | Where {$_.emailaddress -eq $MbxInFile.emailaddress} + + # Wenn das Postfach noch nicht existiert + if($MbxInMailSystem -eq $null) + { + # In allen vorhandenen Einladungen wird geprüft, ob das Postfach schon eingeladen wurde + $MbxInInvitations = $AllInvitations | Where {$_.EMailaddress -eq $MbxInFile.Emailaddress} + # Wenn kein Ergebnis zurückkommt, wird eine Einladung erstellt + if($MbxInInvitations -eq $null) + { + write-verbose "Das Postfach $($MbxInFile.Emailaddress) existiert noch nicht in der Domäne und wird nun eingeladen" + $quotaPools = $WS.GetQuotaPoolsForDomain($primaryDomain) + $QuotaPoolID = $quotapools[0].ID + $PrimaryEMailAddress = $MbxinFile.EMailaddress + $GivenName = $MbxinFile.GivenName + $Surname = $MbxinFile.Sn + $InitialQuotaINMB = $MbxinFile.InitialQuotaInMB + $Mailboxtype = 0 + + # QuotaPoolID,primaryEMailAddress,givenname,surname,quotaINMB,aliasadresses,Mailboxtype,deliverToMailboxAndForward,forwardingSmtpAddress,resourceOwner + $invitationResult = $WS.CreateMailaccountInvitation($quotaPools[0].ID, $PrimaryEMailAddress, $Surname, $GivenName, $InitialQuotaINMB, @(), $mailboxtype, $false, $null, $null) + } + # Wenn ein Ergebnis zurückkommt, kommt eine Statusmeldung der Einladung + else + { + write-verbose "Das Postfach $($MbxInFile.emailaddress) wurde am $(Get-Date $MbxInInvitations.Whencreated -Format "dd.MM.yyyy HH:mm") Uhr in die Domäne eingeladen, aber die Einladung wurde noch nicht angenommen (ActivationCode: $($MbxInInvitations.ActivationCode))" + #$MbxInFile.UPN = "TESTCODE@mai.rwth-aachen.de" + } + } + # Wenn das Postfach schon existiert, aber noch kein UPN in der Datei eingetragen ist. (Die Einladung wurde angenommen und die Datei wird nun bearbeitet) + else + { + write-verbose "Die Einladung für das Postfach $($MbxInFile.emailaddress) wurde nun angenommen. Excel-Datei wird nun mit dem UPN ergänzt" + + # Bearbeiten des Eintrags in der Variable zum späteren Exportieren + $MbxInFile.UPN = $MbxInMailSystem.UPN + # Setzen des Tags zum Überschreiben der Datei + $overwrite = 1 + } + } + # Wenn der UPN schon gesetzt ist + else + { + write-verbose "Der UPN des Accounts $($MbxInFile.Emailaddress) ist schon gesetzt und der Account existiert bereits in der Domäne." + } + } + + # Es wird geprüft, ob das Excelfile abgeändert wurde + if($overwrite -eq 1) + { + # Das abgeänderte Excelfile wird nun abgespeichert + # (da überschreiben nicht geht, wird das alte erst gelöscht und danach das neue erstellt) + write-verbose "Die Excel-Datei wird nun überschrieben mit den neuen Einträgen" + rm $xlsxpath + $File | Export-Excel -Path $xlsxpath -AutoFilter -AutoSize + } + else + { + write-verbose "Es mussten keine Änderungen am Excel-File vorgenommen werden. Excel File wird nicht überschrieben" + } +} #Ende der Funktion Check-Invitations \ No newline at end of file diff --git a/Beispielprojekt/Connect-Webservice.ps1 b/Beispielprojekt/Connect-Webservice.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..544e0cc3153f518c36833ade522c365e1332d90c --- /dev/null +++ b/Beispielprojekt/Connect-Webservice.ps1 @@ -0,0 +1,43 @@ +function Connect-WebService # Verbinden mit dem WebServices +{ + # Setzen der Parameter für die Funktionen + [CmdletBinding()] + param($global:primarydomain="URL der primäre Maildomäne, z.B. itc.rwth-aachen.de") + + # Get-Credentials + $username = "srv123456@rc.rwth-ad.de" + $CredentialPath = "C:\Pfad\Credentials" + $PwdSecureString = Get-Content "$CredentialPath\$Username.cred" | ConvertTo-SecureString + $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $PwdSecureString + + # Mit API verbinden + $uri = "https://ws.rc.rwth-ad.de/ex-cache-ws/APIv04.asmx?WSDL" + + + # Hier wird eine Do-Schleife verwendet, weil das verbinden mit dem ws.rwth-ad.de manchmal nicht klappt + $counter = 0 + do + { + $counter++ + write-verbose "Versuch $counter" + $error.clear() + $global:WS = New-WebServiceProxy -Uri $uri -Credential $cred + if($error.length -ne 0) + { + sleep 2 + } + } + until($error.length -le "0" -or $counter -eq 5) + + if($WS -eq $null -or $counter -eq 5) + { + write-host "Es konnte sich nicht mit dem Mailsystem verbunden werden, Skript wird nun abgebrochen; + Inhalt der Error-Variable: + $error" -foreground Red + break + } + else + { + write-verbose "Verbindungsversuch zum Mailsystem erfolgreich" + } +} diff --git a/PesterTests/MailAdm-Doku.Tests.ps1 b/PesterTests/MailAdm-Doku.Tests.ps1 index dfa0d74b730a6852e7517247be6ad4c71e57665d..df47a840fe2359eb7706d73f419b0671f24bd2b2 100644 --- a/PesterTests/MailAdm-Doku.Tests.ps1 +++ b/PesterTests/MailAdm-Doku.Tests.ps1 @@ -1,18 +1,20 @@ -# These are the Pester Tests in order to demonstrate how the API works +# These are the Pester Tests in order to demonstrate how the API works and +# reflects the following versions API04 MailADM 3.0.3 +# If you need further documentation please check our doku-portal [0] +# or contact our IT-ServiceDesk (servicedesk@itc.rwth-aachen.de) +# [0] https://doc.itc.rwth-aachen.de/dosearchsite.action?queryString=MailAdm # initializing # connection settings -$user = "<MailAdm Serviceaccount>" -$password = "<password>" +$user = "<Service Account>" # e.g. srv123456@rwth-ad.de +$password = "<Password>" $uri = "https://ws.rwth-ad.de/ex-cache-ws/APIv04.asmx?wsDL" -# import functions -. .\connect.ps1 -. .\listquota.ps1 -. .\mailaccounts.ps1 -. .\distributionlist.ps1 - # set variables +# please change the following variables +$existingUPN = "<existing user logon name>" # e.g. ab123456@mustereinrichtung.rwth-aachen.de + +# these variables should work $Primarydomain = "mustereinrichtung.rwth-aachen.de" $SecondaryDomain = "" $existingPersonalMailaccount = "paetzold@mustereinrichtung.rwth-aachen.de" @@ -23,6 +25,15 @@ $distributionlist = "zoo@mustereinrichtung.rwth-aachen.de" $newdistributionmailaddress = "alletiere2@mustereinrichtung.rwth-aachen.de" $newmailaddress = "zebra@mustereinrichtung.rwth-aachen.de" +# import functions +. .\connect.ps1 +. .\listquota.ps1 +. .\mailaccounts.ps1 +. .\distributionlist.ps1 + + + + Describe "MailAdm-Doku" { It "Connection: Establish a connection with Webservice" { $global:ws = new-mailadmconnection -user $user -password $password -uri $uri @@ -48,6 +59,11 @@ Describe "MailAdm-Doku" { $mailaccounts.count | should -BeGreaterOrEqual 0 } + It "get-mailbox: check for existing Logon Credentials and returns the corresponding Mailboxinformation" { + $mailaccount = get-mailbox -webserviceConnection $global:ws -upn $existingUPN + $mailaccount.count | should -Be 1 + } + It "Remove-Mailboxinvitation: dummy test in order to remove all invitations to get a defined infrastructure" { $result = remove-allmailboxinvitation -webserviceconnection $global:ws # check if alll invitations could be deleted @@ -240,6 +256,48 @@ Describe "MailAdm-Doku" { $result | should -Be $true } + It "change: Mailboxtype functional mailbox -> room mailbox" { + # 0 UserMailbox + # 1 Funktionsaccount (in Exchange: UserMailbox) + # 2 RoomMailbox + # 3 EquipmentMailbox + $upn = "fkt_$existingfunctionalmailbox" + $result = change-mailboxtype -webserviceConnection $global:ws -upn $upn -newmailboxtype 2 + $result | should -Be $true + + } + It "change: Mailboxtype room mailbox -> equipment mailbox" { + # 0 UserMailbox + # 1 Funktionsaccount (in Exchange: UserMailbox) + # 2 RoomMailbox + # 3 EquipmentMailbox + $upn = "fkt_$existingfunctionalmailbox" + $result = change-mailboxtype -webserviceConnection $global:ws -upn $upn -newmailboxtype 3 + $result | should -Be $true + + } + + It "change: Mailboxtype equipment mailbox -> functional Mailbox" { + # 0 UserMailbox + # 1 Funktionsaccount (in Exchange: UserMailbox) + # 2 RoomMailbox + # 3 EquipmentMailbox + $upn = "fkt_$existingfunctionalmailbox" + $result = change-mailboxtype -webserviceConnection $global:ws -upn $upn -newmailboxtype 1 + $result | should -Be $true + + } + + It "change: Mailboxtype functional mailbox -> personal Mailbox -->> Error" { + # 0 UserMailbox + # 1 Funktionsaccount (in Exchange: UserMailbox) + # 2 RoomMailbox + # 3 EquipmentMailbox + $upn = "fkt_$existingfunctionalmailbox" + $result = change-mailboxtype -webserviceConnection $global:ws -upn $upn -newmailboxtype 0 + $result | should -Be $false + } + It "create: distribution list" { $displayname = "Zoo" $distributionlist = create-distributionlist -WebserviceConnection $global:ws -displayname $displayname -mailaddress $distributionlist diff --git a/PesterTests/mailaccounts.ps1 b/PesterTests/mailaccounts.ps1 index 2656999f5244c8735b24a73fa848a3845f60d050..530ef7e89c99a69dbb80049ee978dc61ed038b2b 100644 --- a/PesterTests/mailaccounts.ps1 +++ b/PesterTests/mailaccounts.ps1 @@ -8,6 +8,14 @@ function get-mailaccounts { $mailaccounts } +function get-mailbox { + [CmdletBinding()] + param ($webserviceconnection,$upn) + + $mailbox = $webserviceconnection.getMailbox($upn) + $mailbox +} + function add-mailboxinvitation { [CmdletBinding()] param ($webserviceconnection, $quotaPoolID, $primaryEMailAddress, $givenname, $Surname, $QuotaInMB, $Aliasaddresses, $Mailboxtype, $DeliverToMailBoxAndforward, $ForwardingEmailaddress, $Owner) @@ -66,7 +74,6 @@ function change-mailboxforwardingaddress { $result } -function chaange-emailaddresses { } function change-mailboxquota { [CmdletBinding()] @@ -146,4 +153,12 @@ function change-removesendaspermission { $result = $webserviceconnection.RemoveSendAsPermission($mailboxtochange.upn, $user) $result +} + +function change-mailboxtype { + [cmdletBinding()] + param ($webserviceconnection, $upn, $newmailboxtype) + + $result = $webserviceconnection.changemailboxtype($upn,$newmailboxtype) + $result } \ No newline at end of file