Willkommen in der PowerShell Snipp-Lets Ecke.
Hier findet ihr PowerShell Schnipsel für diverse Einsatzzwecke.
Exchange Archive auf Basis eines Domain-Filters als PST exportieren
1 2 3 |
Get-Mailbox | Where-Object { $_.EmailAddresses -match "exchangeblogonline.de" } | ForEach-Object { New-MailboxExportRequest -Mailbox $_.name -FilePath //localhost/t$/pst/$($_.name)_Archive.pst -IsArchive } |
Accepted Domains aus Text-Dokument importieren
1 2 3 |
Get-Content .\domains.txt | % { New-AcceptedDomain -Name $_ -DomainName $_ } |
Getrennte Postfächer auflisten
1 2 3 4 5 6 7 8 9 |
#soft-deleted mailboxes Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "SoftDeleted" } | ft DisplayName,Database,DisconnectDate #disabled mailboxes Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -eq "Disabled" } | ft DisplayName,Database,DisconnectDate |
Exchange OnPremise Implicit Sitzung aufbauen V2 (Remotesitzung)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#Clear Screen Clear-Host #vars $ADPartitionPath = (Get-ADRootDSE).configurationNamingContext $DOMAIN = $env:USERDOMAIN $EXSERVER = (Get-ChildItem "AD:\CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=$DOMAIN,CN=Microsoft Exchange,CN=Services,$ADPartitionPath").Name $SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$($EXSERVER)/powershell" -Authentication Kerberos -AllowRedirection #function import Exchange Session function Import-EXSession{ Import-PSSession $SESSION -DisableNameChecking -AllowClobber } #connect string try{ Import-EXSession #check if connection is open if((Get-PSSession).State -eq "Opened"){ Clear-Host $SERVER = (Get-PSSession).ComputerName Write-Host "`nConnection to [$SERVER] established..." -ForegroundColor Green } }catch{ Write-Host "´nConnection to Exchange failed. Please try again." -ForegroundColor Red } |
Full Access Berechtigung eines Benutzers von alle Mailboxes entfernen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$mailboxes = Get-Mailbox -Resultsize Unlimited $removeFAuser = "A.B@domain.de" $mailboxes | ForEach-Object { Get-MailboxPermission $_.name | Where-Object { ($_.AccessRights -match "FullAccess") ` -and ($_.User -notmatch "SELF") ` -and ($_.IsInherited -eq $False) ` } } | Where-Object { $_.user -match $removeFAuser} | ForEach-Object { Remove-MailboxPermission -Identity $_.Identity ` -User $_.user ` -AccessRights FullAccess ` -InheritanceType All -Confirm:$true } |
PST Import
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$sourcemailbox= "A.B@mary.local" $path = "\\localhost\PST_RESTORE\mary.pst" Get-MailboxImportRequest -Name "$sourcemailbox" | remove-MailboxImportRequest -Confirm function import { New-MailboxImportRequest -Mailbox $sourcemailbox ` -FilePath $path ` -LargeItemLimit unlimited ` -BadItemLimit unlimited ` -AcceptLargeDataLoss ` -Name "$destination" ` -ExcludeDumpster ` -AssociatedMessagesCopyOption MapByMessageClass ` -ConflictResolutionOption ForceCopy ` -ExcludeFolders "Recoverable Items,Posteingang,Gesendete Elemente" #-SourceRootFolder "Gesendete Elemente" -TargetRootFolder "Gesendete Elemente" # -IncludeFolders "/Beispiel" -TargetRootFolder "/Beispiel" ` } import while((Get-MailboxImportRequest -Name "$sourcemailbox").status -ne "Completed"){ Get-MailboxImportRequest -Name "$sourcemailbox" | Get-MailboxImportRequestStatistics | ft TargetMailboxIdentity,PercentComplete,ItemsTransferred, BytesTransferred, BadItemsEncountered sleep 1 } |
Benutzerdefinierten Benachrichtigungstext (DSN) erstellen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
New-SystemMessage -DSNCode 5.1.10 ` -Text " <hr> <b>Die eingegebene E-Mail-Adresse konnte nicht gefunden werden.</b><br/> <br/> Überprüfen Sie die E-Mail-Adresse des Empfängers, und versuchen Sie, die Nachricht erneut zu senden. Wenn das Problem weiterhin besteht, wenden Sie sich bitte an den Service-Desk. <hr> <br/> IT Service-Desk <br/> 0800 123 456 <br/> URL: <a href='http://servicedesk.genesislab.de'>Service-Desk</a> " ` -Internal $True ` -Language de |
RBAC Rollen Mitglieder verwalten
1 2 |
Get-RoleGroup "Organization Management" | Add-RoleGroupMember -Member user Get-RoleGroup "Organization Management" | Remove-RoleGroupMember -Member user |
1 2 3 4 |
ForEach ($group in Get-RoleGroup) { Get-RoleGroupMember $group | Select-Object Name, @{n="Mitglied der RBAC Rolle";e={$group.Name}} } |
Neue Mobile Devices [Active Sync] standardmäßig in die Quarantäne aufnehmen
1 2 |
Set-ActiveSyncOrganizationSettings -DefaultAccessLevel ` Quarantine -AdminMailRecipients admin@contoso.com |
Alle passiven Datenbank-Kopien auf einem Knoten neu replizieren [Seeding]
1 2 |
Get-MailboxDatabaseCopyStatus -Server EX02 | Suspend-MailboxDatabaseCopy -Confirm:$false Get-MailboxDatabaseCopyStatus -Server EX02 | %{Update-MailboxDatabaseCopy -Identity $_.name -SourceServer EX01 -Confirm:$false -DeleteExistingFiles} |
HTML Report Template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
$htmlfile = "html-report.html" $htmlbody = $report | sort "Subject Lines" | ConvertTo-Html -Fragment $htmlhead="<html> <style> BODY{font-family: Arial; font-size: 8pt;} H1{font-size: 22px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;} H2{font-size: 18px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;} H3{font-size: 16px; font-family: 'Segoe UI Light','Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;} TABLE{border: 1px solid black; border-collapse: collapse; font-size: 8pt;} TH{border: 1px solid #969595; background: #dddddd; padding: 5px; color: #000000;} TD{border: 1px solid #969595; padding: 5px; } td.pass{background: #B7EB83;} td.warn{background: #FFF275;} td.fail{background: #FF2626; color: #ffffff;} td.info{background: #85D4FF;} </style> <body> <p>Report of mailbox audit log entries for $mailbox in the last $hours hours.</p>" $htmltail = "</body></html>" $htmlreport = $htmlhead + $htmlbody + $htmltail Write-Host "Writing report data to $htmlfile" $htmlreport | Out-File $htmlfile -Encoding UTF8 |
Do Until Template
1 2 3 4 5 6 7 8 9 |
$service = "app*" do{ Get-Service -DisplayName $service | Start-Service $state = (Get-Service -DisplayName $service).Status }until($state -ne "stopped") Get-Service -DisplayName $service |
Alle passiven Datenbank-Kopien auf einem Knoten neu replizieren (Seeding)
1 2 |
Get-MailboxDatabaseCopyStatus -Server EX02 | Suspend-MailboxDatabaseCopy -Confirm:$false Get-MailboxDatabaseCopyStatus -Server EX02 | %{Update-MailboxDatabaseCopy -Identity $_.name -SourceServer EX01 -Confirm:$false -DeleteExistingFiles} |
IP Adresse(n) in Relay-Connector(s) hinzufügen
1 2 3 4 |
Get-ReceiveConnector "*\*Relay*" | % { $_.RemoteIPRanges += "10.0.0.1", "10.0.0.2", "10.0.0.3" Set-ReceiveConnector $_ -RemoteIPRanges $_.RemoteIPRanges } |
Dot Net Version ermitteln
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
Function Check-DotNetVersion { # Formatting Write-Host " " Write-Host " " $DotNetFound = $False # .NET 4.8 or less check $NETval = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -Name "Release" # Parse through most .NET possibilities: If ($NETval.Release -gt "528049") { Write-Host "Greater than .NET 4.8 is installed - " -NoNewLine Write-Host " Unsupported" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "528049") { Write-Host ".NET 4.8 is installed. Suitable for Exchange 2016 CU13+ - " -NoNewLine Write-Host " Installed" -ForegroundColor Green $DotNetFound = $True } If ($NETval.Release -eq "461814") { Write-Host ".NET 4.7.2 is installed. Suitable for Exchange 2016 CU11+ - " -NoNewLine Write-Host " Installed" -ForegroundColor Green $DotNetFound = $True } If ($NETval.Release -eq "461310") { Write-Host ".NET 4.7.1 is installed. Suitable for Exchange 2016 CU9+ - " -NoNewLine Write-Host " Installed" -ForegroundColor Yellow $DotNetFound = $True } If ($NETval.Release -eq "460805") { Write-Host ".NET 4.7.0 is installed and is not Supported - " -NoNewLine -ForegroundColor White Write-Host " Failed" -ForegroundColor Red DotNetFound = $True } If ($NETval.Release -eq "394806") { Write-Host ".NET 4.6.2 is installed. Supported for Exchange 2016 CU3 to CU9 - " Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "394271") { Write-Host ".NET 4.6.1 is installed. Supported for Exchange 2016 CU2 to CU4 - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "393297") { Write-Host ".NET 4.6.0 is installed and is not Supported - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "379893") { Write-Host ".NET 4.5.2 is installed. Supported for Exchange 2016 CU1 to CU4 - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "378758") { Write-Host ".NET 4.5.1 is installed and is not Supported - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -eq "378389") { Write-Host ".NET 4.5.0 is installed and is not Supported - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($NETval.Release -lt "378389") { Write-Host "Version less than .NET 4.5.0 is installed and is not Supported - " -NoNewLine Write-Host " Failed" -ForegroundColor Red $DotNetFound = $True } If ($DotNetFound -ne $True) { Write-Host 'A valid .NET Version was not found - ' -NoNewLine Write-host 'Failed' -ForegroundColor Red } $global:NetVersion = $NETVal } # End Check-DotNetVersion Check-DotNetVersion |
Nicht mehr verwendete Postfächer auflisten
1 |
Get-Mailbox | ? {$_.WhenMailboxCreated.Month -eq 10} # = 10 Monate |
ECP Zugriff von extern unterbinden
1 2 |
Get-EcpVirtualDirectory | Set-EcpVirtualDirectory -AdminEnabled $false iisreset /noforce |
Datenbank-Whitespace ausgeben [nicht belegter Speicherplatz]
1 2 3 4 5 |
Get-MailboxDatabase -Status | % { $DBName = $_.Name $whiteSpace = $_.AvailableNewMailboxSpace.ToMb() "The $DBName database has $whiteSpace MB of total white space" } |
OWA Verbindung testen
1 |
Test-OwaConnectivity -URL:https://ex01.mary.local/owa -MailboxCredential:(get-credential domain\eddie) |
Exchange AntiMalwareScan aktivieren/deaktivieren
1 2 3 4 5 6 7 8 9 |
cd $ExScripts .\Disable-AntiMalwareScanning.ps1 .\Enable-AntiMalwareScanning.ps1 #update .\Update-MalwareFilteringServer.ps1 Restart-Service MSExchangeTransport |
Neue RBAC Gruppe für SendenImAuftrag [GrantSendOnBehalf] anlegen
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#Neue Rolle und Gruppe erstellen New-ManagementRole -Name "GrantSendOnBehalf" -Parent "Active Directory Permissions" New-RoleGroup -Name "Delegate GrantSendOnBehalf Mailboxes" -Roles "GrantSendOnBehalf" #Alle Commandlets außer Set-ADPermission, Get-ADPermission und Remove-ADPermission entfernen Get-ManagementRoleEntry "GrantSendOnBehalf\*" | where {($_.Name -notlike "Add-ADPermission") -and ($_.Name -notlike "Get-ADPermission") -and ($_.Name -notlike "Remove-ADPermission")} | Remove-ManagementRoleEntry #Parameter entfernen, die nicht verwendet werden sollen z.B. Add-ADPermission -Owner Set-ManagementRoleentry "GrantSendOnBehalf\Add-ADPermission" -Parameters AccessRights, Identity,ExtendedRights,user Set-ManagementRoleentry "GrantSendOnBehalf\Get-ADPermission" -Parameters Identity Set-ManagementRoleentry "GrantSendOnBehalf\Remove-ADPermission" -Parameters AccessRights, Identity,ExtendedRights,user Get-ManagementRoleEntry "GrantSendOnBehalf\*" |
PFX [Zertifikat] importieren und Diensten zuweisen
1 |
Import-ExchangeCertificate -FileData ([Byte[]]$(Get-Content -Path c:\mailCertPrivKeyExportable.pfx -Encoding byte -ReadCount 0)) -Password:(Get-Credential).password | Enable-ExchangeCertificate -Services "IMAP, POP, IIS, SMTP" |
Read-Only-Berechtigung auf Postfach-Ebene konfigurieren
1 |
Add-MailboxPermission -Identity helpdesk -User eadmin -AutoMapping $false -AccessRights Read |
Postmaster-Adresse konfigurieren
1 |
Set-TransportConfig -ExternalPostmasterAddress postmaster@exchangeblogonline.de |
Ordnerstruktur eines Postfaches auflisten
1 2 3 |
Get-Mailbox eadmin | select alias | %{ Get-MailboxFolder -Recurse } |
Aufbewahrung [Litigation Hold] für eine Mailbox aktivieren
1 2 |
Get-Mailbox -RecipientTypeDetails Usermailbox| Set-Mailbox -LitigationHoldEnabled $true |
Transportverschlüsselung [TLS] für Empfangs-Konnektor konfigurieren [kann auch für Sende-Konnektor verwendet werden]
1 2 3 4 5 6 7 |
$Cert = Get-ExchangeCertificate -Thumbprint AB90A1B015A596D2461E3F9BF808BD43B5385F45 $TLSCertificateName = "<i>$($Cert.Issuer)<s>$($Cert.Subject)" $TLSCertificateName Set-ReceiveConnector "EX01\INBOUND-INTERNET" -TlsCertificateName $TLSCertificateName Set-ReceiveConnector "INBOUND-INTERNET" -RequireTLS $true |
Raumpostfächer [erste 50] auf eine andere Datenbank verschieben [z.B. bei einer Migration] und in 14 Tagen abschließen
1 2 3 4 5 6 7 |
Get-Mailbox -RecipientTypeDetails RoomMailbox | select -First 50 | New-MoveRequest -TargetDatabase MBDB02 -CompleteAfter (Get-Date).AddDays(14) -BadItemLimit Unlimited -AcceptLargeDataLoss -BatchName RoomMailbox |
E-Mail via Telnet versenden
1 2 3 4 5 6 7 8 |
ehlo ex01.mary.local mail from:eddie@mary.local rcpt to:admin@mary.local data subject:Testmail Dies ist eine Testnachricht . Enter |
Exchange Banner ändern
1 2 |
Get-ReceiveConnector "EX01\Default Frontend EX01" | Set-ReceiveConnector -Banner "220 EX-DEFAULT-25" Get-ReceiveConnector "EX01\Default Frontend EX01" | fl banner |
Nachrichten in Postfächern von Mitgliedern eines Verteilers suchen [Suchen nach Betreff]
1 2 3 |
Get-DistributionGroupMember Dispoteam@domain.de | %{ Search-Mailbox $_.name -SearchQuery "subject:'Ticket IN-77777- Testmail'" -EstimateResultOnly } |
Alle Datenbanken auf ein anderes Laufwerk verschieben
1 2 3 4 5 6 7 8 |
foreach($i in Get-MailboxDatabase -Server EX01) { $DBName = $i.Name Move-DatabasePath -Identity $DBName ` -EdbFilePath "S:\Databases\$DBName\Database\$DBName.edb" ` -LogFolderPath "S:\Databases\$DBName\Logs" ` -Confirm:$false ` -Force } |
Datenbank-Pfad auf ein anderes Laufwerk verschieben
1 2 3 4 5 |
Move-DatabasePath -Identity DB1 ` -EdbFilePath F:\Databases\DB1\Database\DB1.edb ` -LogFolderPath F:\Databases\DB1\Logs ` -Confirm:$false ` -Force |
Nachrichten aus Postfächern löschen (z.B. versehentlich versendete Nachrichten)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#sollten keine Ergebnisse ausgegeben werden, ersetzt bitte "subject" mit "thema" #z.B.: -SearchQuery "Thema:'IMPORTANT | Gehaelter' #get results from A.B@DOMAIN.COM and store into RESTORE-MAILBOX Get-Mailbox -ResultSize unlimited | Search-Mailbox ` -SearchQuery "Subject:'IMPORTANT | Gehaelter' ` AND from:'A.B@DOMAIN.COM'" ` -TargetMailbox "RESTORE-MAILBOX" ` -TargetFolder "RESULTS-IMPORTANT-GEHAELTER" #delete results in all mailboxes Get-Mailbox -ResultSize unlimited | ` Search-Mailbox -SearchQuery "Subject:'IMPORTANT | Gehaelter'" -TargetMailbox "RESTORE-MAILBOX" -TargetFolder "RESULTS-IMPORTANT-GEHAELTER" -DeleteContent -Confirm:$false -Force #delete results without target folder Search-Mailbox -identity zeitarbeit@domain.de ` -SearchQuery "Subject:mail1.domain.de Mail delivery failed" ` -DeleteContent -Confirm:$false -Force #delete attachtment where match gehaltsabrechnung get-mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery "attachment:%gehaltsabrechnung%.xlsx'" -DeleteContent -Confirm:$false -force |
Postfach Dumpster löschen
1 2 3 4 |
Search-Mailbox -Identity "MAILBOX" -SearchDumpsterOnly -DeleteContent Get-MailboxFolderStatistics -Identity "MAILBOX" -FolderScope RecoverableItems | Format-Table Name,FolderAndSubfolderSize,ItemsInFolderAndSubfolders -Auto |
Exchange Zertifikat Dienste zuweisen
1 |
Enable-ExchangeCertificate -Thumbprint 5113ae0233a72fccb75b1d0198628675333d020b -Services POP,IMAP,SMTP,IIS |
Exchange Virtual Directories konfigurieren
Quelle: https://www.frankysweb.de/exchange-2016-die-basiskonfiguration/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
$servername = "HOSTNAME" $internalhostname = "mail.contoso.com" $externalhostname = "mail.contoso.com" $autodiscoverhostname = "autodiscover.contoso.com" $owainturl = "https://" + "$internalhostname" + "/owa" $owaexturl = "https://" + "$externalhostname" + "/owa" $ecpinturl = "https://" + "$internalhostname" + "/ecp" $ecpexturl = "https://" + "$externalhostname" + "/ecp" $ewsinturl = "https://" + "$internalhostname" + "/EWS/Exchange.asmx" $ewsexturl = "https://" + "$externalhostname" + "/EWS/Exchange.asmx" $easinturl = "https://" + "$internalhostname" + "/Microsoft-Server-ActiveSync" $easexturl = "https://" + "$externalhostname" + "/Microsoft-Server-ActiveSync" $oabinturl = "https://" + "$internalhostname" + "/OAB" $oabexturl = "https://" + "$externalhostname" + "/OAB" $mapiinturl = "https://" + "$internalhostname" + "/mapi" $mapiexturl = "https://" + "$externalhostname" + "/mapi" $aduri = "https://" + "$autodiscoverhostname" + "/Autodiscover/Autodiscover.xml" Get-OwaVirtualDirectory -Server $servername | Set-OwaVirtualDirectory -internalurl $owainturl -externalurl $owaexturl Get-EcpVirtualDirectory -server $servername | Set-EcpVirtualDirectory -internalurl $ecpinturl -externalurl $ecpexturl Get-WebServicesVirtualDirectory -server $servername | Set-WebServicesVirtualDirectory -internalurl $ewsinturl -externalurl $ewsexturl Get-ActiveSyncVirtualDirectory -Server $servername | Set-ActiveSyncVirtualDirectory -internalurl $easinturl -externalurl $easexturl Get-OabVirtualDirectory -Server $servername | Set-OabVirtualDirectory -internalurl $oabinturl -externalurl $oabexturl Get-MapiVirtualDirectory -Server $servername | Set-MapiVirtualDirectory -externalurl $mapiexturl -internalurl $mapiinturl Get-OutlookAnywhere -Server $servername | Set-OutlookAnywhere -externalhostname $externalhostname -internalhostname $internalhostname -ExternalClientsRequireSsl:$true -InternalClientsRequireSsl:$true -ExternalClientAuthenticationMethod 'Negotiate' Get-ClientAccessServer $servername | Set-ClientAccessServer -AutoDiscoverServiceInternalUri $aduri Get-OwaVirtualDirectory -Server $servername | fl server, externalurl, internalurl Get-EcpVirtualDirectory -server $servername | fl server, externalurl, internalurl Get-WebServicesVirtualDirectory -server $servername | fl server, externalurl, internalurl Get-ActiveSyncVirtualDirectory -Server $servername | fl server, externalurl, internalurl Get-OabVirtualDirectory -Server $servername | fl server, externalurl, internalurl Get-MapiVirtualDirectory -Server $servername | fl server, externalurl, internalurl Get-OutlookAnywhere -Server $servername | fl servername, ExternalHostname, InternalHostname Get-ClientAccessServer $servername | fl name, AutoDiscoverServiceInternalUri |
Mailboxes größer 2 GB in eine andere Datenbank verschieben
1 2 3 4 5 6 7 8 9 10 11 |
$mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox ` | Get-MailboxStatistics | ` ? {$_.TotalItemSize -gt 2GB} $mailboxes | % { ` New-MoveRequest $_.Alias ` -BatchName 'Large Mailboxes' ` -TargetDatabase DB2 ` } Get-MoveRequest -BatchName 'Large Mailboxes' |
2010/2016 Koexistenz Proxy Public Folder erstellen (Zugriff auf Exchange 2010 Public Folder mit Exchange 2016 Postfach)
1 2 3 4 5 6 7 |
New-MailboxDatabase -Server EX01 -Name PFProxyDatabase -IsExcludedFromProvisioning $true New-Mailbox -Name PFProxyMailbox -Database PFProxyDatabase -UserPrincipalName PFProxyMailbox1@domain.com Set-Mailbox -Identity PFProxyMailbox1 -HiddenFromAddressListsEnabled $true Set-OrganizationConfig -PublicFoldersEnabled Remote -RemotePublicFolderMailboxes PFProxyMailbox1 Mount-Database "PFProxyDatabase" Get-OrganizationConfig |fl *public* |
Public Folder Report
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. # THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. # We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object # code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market # Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product # in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against # any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code. Write-Progress -Activity "Finding Public Folders" -Status "running get-publicfolders -recurse" $folders = get-publicfolder -recurse -resultsize unlimited $arFolderData = @() $totalfolders = $folders.count $i = 1 foreach ($folder in $folders) { $statusstring = "$i of $totalfolders" write-Progress -Activity "Gathering Public Folder Information" -Status $statusstring -PercentComplete ($i/$totalfolders*100) $folderstats = get-publicfolderstatistics $folder.identity $folderdata = new-object Object $folderdata | add-member -type NoteProperty -name FolderName $folder.name $folderdata | add-member -type NoteProperty -name FolderPath $folder.identity $folderdata | add-member -type NoteProperty -name LastAccessed $folderstats.LastAccessTime $folderdata | add-member -type NoteProperty -name LastModified $folderstats.LastModificationTime $folderdata | add-member -type NoteProperty -name Created $folderstats.CreationTime $folderdata | add-member -type NoteProperty -name ItemCount $folderstats.ItemCount $folderdata | add-member -type NoteProperty -name Size $folderstats.TotalItemSize $folderdata | Add-Member -type NoteProperty -Name Mailenabled $folder.mailenabled if ($folder.mailenabled) { #since there is no guarentee that a public folder has a unique name we need to compare the PF's entry ID to the recipient objects external email address $entryid = $folder.entryid.tostring().substring(76,12) $primaryemail = (get-recipient -filter "recipienttype -eq 'PublicFolder'" -resultsize unlimited | where {$_.externalemailaddress -like "*$entryid"}).primarysmtpaddress $folderdata | add-member -type NoteProperty -name PrimaryEmailAddress $primaryemail } else { $folderdata | add-member -type NoteProperty -name PrimaryEmailAddress "Not Mail Enabled" } if ($folderstats.ownercount -gt 0) { $owners = get-publicfolderclientpermission $folder.identity | where {$_.accessrights -like "*owner*"} $ownerstr = "" foreach ($owner in $owners) { $ownerstr += $owner.user.exchangeaddressbookdisplayname + "," } } else { $ownerstr = "" } $folderdata | add-member -type NoteProperty -name Owners $ownerstr $arFolderData += $folderdata $i++ } $arFolderData | export-csv -path PublicFolderData.csv -notypeinformation |
Anonymous Relay Konnektor erstellen
1 2 3 4 5 |
#bitte hier beachten, dass ein gesamtes Netz freigeben wird! New-Receiveconnector -Name "Internal_Relay" -RemoteIPRange ("192.168.178.0/24") -TransportRole “FrontendTransport” -Bindings (“0.0.0.0:25”) -usage “Custom” -Server "EX01" Set-ReceiveConnector -identity "Internal_Relay" -PermissionGroups “AnonymousUsers” Get-ReceiveConnector "EX01\Internal_Relay" | Add-ADPermission -User “NT-AUTORITÄT\ANONYMOUS-ANMELDUNG” -ExtendedRights “Ms-Exch-SMTP-Accept-Any-Recipient” -ea 0 Get-ReceiveConnector "EX01\Internal_Relay" | Add-ADPermission -User “NT AUTHORITY\ANONYMOUS LOGON” -ExtendedRights “Ms-Exch-SMTP-Accept-Any-Recipient” -ea 0 |
Datenbanken nach Aktivierungs-Priorität verteilen
1 2 3 4 |
cd $exscripts .\RedistributeActiveDatabases.ps1 –DagName (Get-databaseavailabilitygroup).name ` –BalanceDBsByActivationPreference ` –Confirm:$false |
Kalender Standard-Berechtigungen für alle Mailboxes ändern <Reviewer>
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$mailboxes = Get-Mailbox -ResultSize Unlimited $mailboxes | % { $calendar = Get-MailboxFolderPermission ` "$($_.alias):\Kalender" -User Default if (!($calendar.AccessRights)) { Add-MailboxFolderPermission "$($_.alias):\Kalender" ` -User Default -AccessRights Reviewer } if ($calendar.AccessRights -ne "Reviewer") { Set-MailboxFolderPermission "$($_.alias):\Kalender" ` -User Default -AccessRights Reviewer } } |
Mailboxsize in MB
1 2 3 4 5 |
Get-Mailbox -Resultsize Unlimited | Get-MailboxStatistics | Select DisplayName, ` @{name = ”TotalItemSize (MB)”; expression = ` {[math]::Round( ($_.TotalItemSize.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”, ””) / 1MB), 2)}}, ` ItemCount | Sort “TotalItemSize (MB)” -Descending |
PowerShell Parameter in ein Skript implementieren
1 2 3 4 5 6 7 8 9 10 11 |
[CmdletBinding()] Param( [Parameter(Mandatory = $true, HelpMessage = "Bitte Mailboxnamen eingeben")] [ValidateNotNullorEmpty()] [string] $mailbox, [Parameter(Mandatory = $true, HelpMessage = "Bitte den PST FolderName eintragen")] [ValidateNotNullorEmpty()] [string] $foldername, [Parameter(Mandatory = $true, HelpMessage = "Bitte den PST-Pfad eintragen:")] [ValidateNotNullorEmpty()] [string] $pstpath ) |
MoveRequest Status Loop
1 2 3 4 5 |
While ($True) { Get-MoveRequest | ? {$_.Status -ne 'Completed'} | Get-MoveRequestStatistics Start-Sleep 5 Clear-Host } |
Kopie gesendeter Nachrichten in Shared Mailbox ablegen (Exchange Online)
1 2 3 4 |
Get-Mailbox -ResultSize Unlimited| ? {$_.RecipientTypeDetails -match "SharedMailbox"} |` % {set-mailbox $_.UserprincipalName -MessageCopyForSentAsEnabled $True} Get-Mailbox -ResultSize Unlimited | ? {$_.RecipientTypeDetails -match "UserMailbox"} | ` % {set-mailbox $_.UserprincipalName -MessageCopyForSendOnBehalfEnabled $True} |
Kopie gesendeter Nachrichten in Shared Mailbox ablegen (OnPremise)
1 2 3 4 |
Get-Mailbox | ?{$_.RecipientTypeDetails -match "SharedMailbox"} | ` %{set-mailbox $_ -MessageCopyForSentAsEnabled $True} Get-Mailbox | ?{$_.RecipientTypeDetails -match "SharedMailbox"} | ` %{set-mailbox $_ -MessageCopyForSendOnBehalfEnabled $True} |
PST Import
1 2 3 4 5 6 7 8 9 10 11 12 |
function PSTImport{ $pst = Read-Host "UNC-Pfad z.B.: \\dc01\Share\PST\schulungsaccount3.pst" $zielpostfach = Read-Host "Bei wem soll die PST eingebunden werden?" $sourceuser = Read-Host "Von wem stammt die PST-Datei?" New-MailboxImportRequest -Mailbox $zielpostfach -FilePath $pst ` -TargetRootFolder "Archiv_$sourceuser" -batchname "$zielpostfach" Start-Sleep 5 Get-MailboxImportRequest -batchname "$zielpostfach" | ` Get-MailboxImportRequestStatistics | ft } PSTImport |
PST OU Mailbox-Export
1 2 3 4 5 6 7 8 |
$user = Get-Mailbox -OrganizationalUnit ` "OU=schulung,OU=koeln,OU=deutschland,OU=europa,OU=standorte,OU=exchangeblogonline.de,DC=exchangeblogonline,DC=de" $share = "\\dc01\Share\PST" foreach ($var in $user){ New-MailboxExportRequest -Mailbox $var.name ` -FilePath "$share\$var.pst" -Batchname "$user.userprincipalname" } |
Exchange Implicit Sitzung aufbauen (Remotesitzung)
1 2 3 4 5 |
#servername oder nlb adresse angeben $fqdn = "casarray.exchangeblogonline.de" $Session = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://$fqdn/powershell -Authentication Kerberos -AllowRedirection Import-PSSession $Session |
Office 365 Remotesitzung importieren
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$proxysettings = New-PSSessionOption $Session = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential ` -Authentication Basic -AllowRedirection Start-Sleep 2 ###################################################################### #o365 session Import-PSSession $Session if (!(Get-PSSession)) { Write-Host "Trying Office 365 connection with IE Proxy settings..." -ForegroundColor Yellow $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection -SessionOption $proxysettings Start-Sleep 1 Import-PSSession $Session -AllowClobber -ErrorAction SilentlyContinue } if (!(Get-PSSession)) { Write-Host "Connection to Office 365 has failed!" -ForegroundColor Red } |
E-Mails via Send-MailMessage versenden
1 2 3 4 5 |
Send-MailMessage -To user@domain.de ` -From exreport@domain.de ` -Subject "Test E-Mail" ` -Body "Dies ist eine Testnachricht" ` -SmtpServer server.domain.de |