Exchange Snippets Flohmarkt für verschiedene Einsatzbereiche
Exchange Archive auf Basis eines Domain-Filters als PST exportieren
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
Get-Content .\domains.txt | % {
New-AcceptedDomain -Name $_ -DomainName $_
}
Getrennte Postfächer auflisten
#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)
#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 allen Postfächern entfernen
PowerShell
$mailboxes = Get-Mailbox -Resultsize Unlimited
#full access permission for this user will be removed
$removeFAuser = "john.smith@contoso.com"
$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
PowerShell
#pst will be imported into this mailbox
$targetmailbox= "john.doe@contoso.com"
#location of pst file
$path = "\\localhost\PST_RESTORE\mary.pst"
Get-MailboxImportRequest -Name "$sourcemailbox" | remove-MailboxImportRequest -Confirm
#function to start import
function import {
New-MailboxImportRequest -Mailbox $sourcemailbox `
-FilePath $path `
-LargeItemLimit unlimited `
-BadItemLimit unlimited `
-AcceptLargeDataLoss `
-Name "PST Import $targetmailbox" `
-ExcludeDumpster `
-AssociatedMessagesCopyOption MapByMessageClass `
-ConflictResolutionOption ForceCopy
#-ExcludeFolders "Recoverable Items,Posteingang,Gesendete Elemente"
#-SourceRootFolder "Gesendete Elemente" -TargetRootFolder "Gesendete Elemente"
# -IncludeFolders "/Beispiel" -TargetRootFolder "/Beispiel" `
}
#execute import
import
#monitor progress
while((Get-MailboxImportRequest -Name "$targetmailbox").status -ne "Completed"){
Get-MailboxImportRequest -Name "$sourcemailbox" |
Get-MailboxImportRequestStatistics |
ft TargetMailboxIdentity,PercentComplete,ItemsTransferred, BytesTransferred, BadItemsEncountered
sleep 1
}
Benutzerdefinierten Benachrichtigungstext (DSN) erstellen
PowerShell
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
PowerShell
#add user to role managament group
Get-RoleGroup "Organization Management" | Add-RoleGroupMember -Member user
#remove user to from role managament group
Get-RoleGroup "Organization Management" | Remove-RoleGroupMember -Member user
#show me members of role managament group
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
PowerShell
Set-ActiveSyncOrganizationSettings -DefaultAccessLevel Quarantine -AdminMailRecipients chuck.norris@contoso.com
IP Adresse(n) in Relay-Connector(s) hinzufügen
PowerShell
ReceiveConnector "*\*Relay*" | % {
$_.RemoteIPRanges += "10.0.0.1", "10.0.0.2", "10.0.0.3"
Set-ReceiveConnector $_ -RemoteIPRanges $_.RemoteIPRanges
}
Dot Net Version ermitteln
PowerShell
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
PowerShell
Get-Mailbox | ? {$_.WhenMailboxCreated.Month -eq 10} # = 10 Monate
ECP Zugriff von extern unterbinden
PowerShell
Get-EcpVirtualDirectory | Set-EcpVirtualDirectory -AdminEnabled $false
iisreset /noforce
Datenbank-Whitespace ausgeben [nicht belegter Speicherplatz]
PowerShell
Get-MailboxDatabase -Status | % {
$DBName = $_.Name
$whiteSpace = $_.AvailableNewMailboxSpace.ToMb()
"The $DBName database has $whiteSpace MB of total white space"
}
OWA Verbindung testen
PowerShell
Test-OwaConnectivity -URL:https://ex01.mary.local/owa -MailboxCredential:(get-credential domain\eddie)
Exchange AntiMalwareScan aktivieren/deaktivieren
PowerShell
cd $ExScripts
.\Disable-AntiMalwareScanning.ps1
.\Enable-AntiMalwareScanning.ps1
#update
.\Update-MalwareFilteringServer.ps1
Restart-Service MSExchangeTransport
Neue RBAC Gruppe für SendenImAuftrag [GrantSendOnBehalf] anlegen
PowerShell
#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
PowerShell
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
PowerShell
Add-MailboxPermission -Identity helpdesk -User eadmin -AutoMapping $false -AccessRights Read
Postmaster-Adresse konfigurieren
PowerShell
Set-TransportConfig -ExternalPostmasterAddress postmaster@exchangeblogonline.de
Ordnerstruktur eines Postfaches auflisten
PowerShell
Get-Mailbox eadmin | select alias | %{
Get-MailboxFolder -Recurse
}
Aufbewahrung [Litigation Hold] für eine Mailbox aktivieren
PowerShell
Get-Mailbox -RecipientTypeDetails Usermailbox|
Set-Mailbox -LitigationHoldEnabled $true
Transportverschlüsselung [TLS] für Empfangs-Konnektor konfigurieren [kann auch für Sende-Konnektor verwendet werden]
PowerShell
$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
PowerShell
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
PowerShell
ehlo ex01.contoso.com
mail from:eddie@contoso.com
rcpt to:admin@mcontoso.com
data
subject:Testmail
Dies ist eine Testnachricht
.
<Enter>
Exchange Receive Connector Banner ändern
PowerShell
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]
PowerShell
Get-DistributionGroupMember mbowen@contoso.com | %{
Search-Mailbox $_.name -SearchQuery "subject:'Ticket IN-77777- Testmail'" -EstimateResultOnly
}
Alle Datenbanken auf ein anderes Laufwerk verschieben
PowerShell
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 und Logfiles auf ein anderes Laufwerk verschieben
PowerShell
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 mit Search-Mailbox (z.B. versehentlich versendete Nachrichten)
PowerShell
#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 (bereinigte Elemente aus dem Ordner “gelöschte Elemente”)
PowerShell
Search-Mailbox -Identity "MAILBOX" -SearchDumpsterOnly -DeleteContent
Get-MailboxFolderStatistics -Identity "MAILBOX" -FolderScope RecoverableItems |
Format-Table Name,FolderAndSubfolderSize,ItemsInFolderAndSubfolders -Auto
Exchange Zertifikat Dienste zuweisen
PowerShell
Enable-ExchangeCertificate -Thumbprint 5113ae0233a72fccb75b1d0198628675333d020b -Services POP,IMAP,SMTP,IIS
Exchange Virtual Directories konfigurieren
Quelle: https://www.frankysweb.de/exchange-2016-die-basiskonfiguration/
PowerShell
$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
PowerShell
$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)
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
# 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
#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
cd $exscripts .\RedistributeActiveDatabases.ps1 –DagName (Get-databaseavailabilitygroup).name ` –BalanceDBsByActivationPreference ` –Confirm:$false
Kalender Standard-Berechtigungen für alle Mailboxes ändern <Reviewer>
$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
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
[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
While ($True) { Get-MoveRequest | ? {$_.Status -ne 'Completed'} | Get-MoveRequestStatistics Start-Sleep 5 Clear-Host }
Kopie gesendeter Nachrichten in Shared Mailbox ablegen (Exchange Online)
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)
Get-Mailbox | ?{$_.RecipientTypeDetails -match "SharedMailbox"} | ` %{set-mailbox $_ -MessageCopyForSentAsEnabled $True} Get-Mailbox | ?{$_.RecipientTypeDetails -match "SharedMailbox"} | ` %{set-mailbox $_ -MessageCopyForSendOnBehalfEnabled $True}
PST Import
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
$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)
#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
$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
Send-MailMessage -To user@domain.de ` -From exreport@domain.de ` -Subject "Test E-Mail" ` -Body "Dies ist eine Testnachricht" ` -SmtpServer server.domain.de