#1. Autodiscovery prüfen Zeil 47 #2. Exchange Zertifikat anhand Autodiscovery prüfen und evtl. als vertraunswürdig importieren #3. Exchange WebApi installieren und Variable ändern #4. Impersonation setzen (New-ManagementRoleAssignment -Name:"Administrator" -Role:ApplicationImpersonation -User:Administrator@domain.local) und in Zeile 44 hinterlegen #5. set-executionpolicy unresticted [string]$info = "White" # Color for informational messages [string]$warning = "Yellow" # Color for warning messages [string]$error = "Red" # Color for error messages [string]$LogFile = "E:\Log.txt" # Path of the Log File [String]$FolderName = "MailStoreArchiv" Clear-Host Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 function CreateFolder($MailboxName) { Write-host "Creating Folder for Mailbox Name:" $MailboxName -foregroundcolor $info Add-Content $LogFile ("Creating Folder for Mailbox Name:" + $MailboxName) #Change the user to Impersonate $service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$MailboxName); Write-Host "Create the folder object" $oFolder = new-object Microsoft.Exchange.WebServices.Data.Folder($service) $oFolder.DisplayName = $FolderName Write-Host "Call Save to actually create the folder" $oFolder.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::msgfolderroot) Write-host "Folder Created for " $MailboxName -foregroundcolor $warning Add-Content $LogFile ("Folder Created for " + $MailboxName) $service.ImpersonatedUserId = $null } #Change the name of the folder Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2) # Set the Credentials $service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("Administrator","password","domain.local") # Change the URL to point to your cas server $service.Url= new-object Uri("https://autodiscoverurl.local/EWS/Exchange.asmx") # Set $UseAutoDiscover to $true if you want to use AutoDiscover else it will use the URL set above $UseAutoDiscover = $false $Mailboxes = get-mailbox digitaldata $Mailboxes = get-mailbox -ResultSize Unlimited | Where-Object {$_.displayname -notlike 'SystemMailbox*' -AND $_.displayname -notlike 'Microsoft System Attendant*' -AND $_.name -notlike 'DiscoverySearchMailbox*' } | ?{-not ($_.User -match “NT AUTHORITY”) -and -not ($_.User -match “NT-AUTORITÄT”)} $Mailboxes | foreach-object { $WindowsEmailAddress = $_.WindowsEmailAddress.ToString() if ($UseAutoDiscover -eq $true) { Write-host "Autodiscovering.." -foregroundcolor $info $UseAutoDiscover = $false $service.AutodiscoverUrl($WindowsEmailAddress) Write-host "Autodiscovering Done!" -foregroundcolor $info Write-host "EWS URL set to :" $service.Url -foregroundcolor $info } #To catch the Exceptions generated trap [System.Exception] { Write-host ("Error: " + $_.Exception.Message) -foregroundcolor $error; Add-Content $LogFile ("Error: " + $_.Exception.Message); continue; } CreateFolder($WindowsEmailAddress) }