Exchange Powershell

From WikiWiki
Jump to navigation Jump to search
powershell connect

disable certificate check on winrm psremoting

$UserCredential = Get-Credential
$skipCN = New-PSSessionOption -SkipCNCheck -SkipCACheck -SkipRevocationCheck
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://owa.contoso.com/powershell/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -SessionOption $skipcn
srv records oplijsten
$list=get-accepteddomain | select domainname
$list.domainname.smtpdomain.domain | % {$var="_autodiscover._tcp." + $_ ; Resolve-DnsName $var -type srv} | ft name, nametarget
alle gebruikers in ou oplijsten, en dan voor iedere gebruiker die al een @domain.eu mailadres hebben dit op primary zetten
$group=get-mailbox -OrganizationalUnit "ou=users,dc=contoso,dc=com"
foreach($user in $group)
{
	$set=get-mailbox $user | select emailaddresses
	$themailaddress=$set.emailaddresses | where {$_.smtpaddress -like "*@domain.eu"}
	write-host $themailaddress
	set-mailbox $user -PrimarySmtpAddress $themailaddress
}
alle mailadressen oplijsten van ene bepaalde ou en exporteren naar een csv-file
Get-Mailbox -OrganizationalUnit "ou=users,dc=contoso,dc=com"  |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-CSV C:\users\mendel\Desktop\file.csv -NoTypeInformation
alle users oplijsten die een specifiek mailadres hebben (of *@domein.com ofzo)
get-recipient -results unlimited | where {$_.emailaddresses -match "email-address-here"} | select name,emailaddresses,recipienttype
alle personen in een dl oplijsten en exporteren naar een bestand met gelijkaardige naam
$lijst=""group@blabla.be","verlof@blabla"

foreach($name in $lijst)
{
write-host $name
Get-Group $name |  select-object -ExpandProperty members | select name | Export-Csv c:\users\mendel\desktop\iadvise\$name.txt
}


Verschillende mensen toevoegen aan een DL

Indien mailbox not found, wordt er een contact aangemaakt!

###################################
## Add members to DL             ##
## Create contact when necessary ##
###################################

## Set some variables...
$OU = "Contacts"
$DLname = (Read-Host "Please enter the name of the DL")

#$NewUsers = get-content .\dudes.txt
$NewUsers = @()
do {
 $input = (Read-Host "Please enter the email addresses to add")
 if ($input -ne '') {$NewUsers += $input}
}
until ($input -eq '')


foreach ($NewUser in $NewUsers) {
  $newusermb = get-recipient -identity $NewUSer
  if ($newusermb) {
    write-host "User $NewUser exists in system! Adding to DL $DLname ..."
    add-distributiongroupmember -identity $DLname -member $NewUser
  } else {
    write-host "$NewUser is external, let's make a contact! "
    ## make contact and add to DL!
	$alias = $newuser.replace("@","-at-")
	New-Mailcontact -Name "$NewUser - remote" -ExternalEmailAddress $NewUser -alias $alias -OrganizationalUnit $OU
	add-distributiongroupmember -identity $DLname -member $NewUser
  }

}
Write-Host "The DL $DLname now has the following members:"
Get-Distributiongroupmember $DLname | select DisplayName,PrimarySMTPAddress
alias toevoegen
Set-Mailbox 'gebruikersnaam' -EmailAddresses @{Add='alias@domein.com'}
aantal connected users tonen
do
{
$RPC =Get-Counter "\MSExchange RpcClientAccess\User Count" -computername "casserver"
$OWA =Get-Counter "\MSExchange OWA\Current Unique Users" -computername "casserver"
$POP = Get-Counter “\MSExchangePop3(1)\Connections Current” -ComputerName "casserver"
$IMAP = get-counter “\MSExchangeImap4(1)\Current Connections” -ComputerName "casserver"
$csa=New-Object PSObject -Property @{
        Server = "casserver"
        "rpc" = $RPC.CounterSamples[0].CookedValue
        "owa" = $OWA.CounterSamples[0].CookedValue
	"pop" = $POP.CounterSamples[0].CookedValue
	"imap" = $IMAP.CounterSamples[0].CookedValue
      }


write-host $csa.server", pop:" $csa.pop ", imap" $csa.imap ", owa: " $csa.owa, "rpc: " $csa.rpc
	  
$exit=Read-Host "exit"
}
while(($exit -eq "n") -or ($exit -eq "no"))


full access claimen op een aantal mailboxen
get-mailbox -identity "searchstring*" | Add-MailboxPermission -User username -AccessRights fullaccess


rechten op public folder oplijsten
$list=Get-PublicFolder "\meeting rooms\" -Recurse
foreach($entry in $list)
{
 write-host "---------------------------------------------------------------------------"
 $name=$entry.Name
 write-host $name
 Get-PublicFolderClientPermission "\meeting rooms\$name"
}


maintenance schedule oplijsten
Get-MailboxServer | Get-mailboxDatabase | Select ServerName, Name, MaintenanceSchedule | Export-csv c:\MaintenaceSchedule.csv -Force -NoTypeInformation


pst importeren

Om een pst te importeren of te exporteren in exchange heb je speciale rechten nodig. Dit omdat standaard "data gelekt" kan worden en andere privacy schermutselingen... Via Rbacmanager is de groep "Custom Mailbox Import Export" aangemaakt die deze rechten heeft. (Via aduc in groep steken is voldoende).

De pst in kwestie moet op een gedeelde folder staan die leesbaar is door "Exchange Trusted Subsystem" of "everyone".

New-MailboxImportRequest -Mailbox username -FilePath "\\locatie\map\bestand.pst"

Kan ook met flag -IsArchive die de pst onmiddellijk in het archief pompt

Met -TargetRootFolder "RecoveredFiles" kunt ge de locatie binnen uwe mailbox bepalen...

http://technet.microsoft.com/en-us/library/ff607310%28v=exchg.141%29.aspx


Om op te volgen: doe nen get-mailboximportrequest of iets specifieker

Get-MailboxImportRequest -Status inprogress | Get-MailboxImportRequestStatistics

Een import kan falen door verschillende redenen: meestal gewoon 1 of andere file die corrupt geraakt is doorheen de jaren (waardeloze rommel!). Opvolgen en oplossen kan via volgende powershell-commando's!

Get-MailboxImportRequest -status failed | set-mailboximportrequest -baditemlimit 5
get-mailboximportrequest -status failed | resume-mailboximportrequest
pst exporteren

Dezelfde beperking als bij import: je moet lid zijn van de groep "custom mailbox import export" in ad.

New-MailboxExportRequest -Mailbox username -FilePath "\\locatie\map\bestand.pst"

http://technet.microsoft.com/en-us/library/ff607299%28v=exchg.141%29.aspx

zoeken wie wat heeft gedaan

Gebeurt met search-adminauditlog

Wat er is gebeurd met mailbox x?

Search-AdminAuditLog -ObjectIds "contoso.com/users/gebruiker x"

Wat heeft adminy allemaal gedaan

http://technet.microsoft.com/en-us/library/ff522360%28v=exchg.141%29.aspx


message tracking in powershell
Get-MessageTrackingLog -Server Mailbox01 -Start "08/15/2013 09:00:00" -End "08/19/2013 17:00:00" -Sender "john@contoso.com"
get-mailboxserver | Get-MessageTrackingLog -Start "08/15/2013 09:00:00" -End "08/19/2013 17:00:00" -Recipients "support@company.be"


grootte mailboxdatabase
    Get-MailboxDatabase | foreach-object {add-member -inputobject $_ -membertype noteproperty -name mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter ('name=''' + $_.edbfilepath.pathname.replace("\","\\") + '''')).filesize / 1GB),2)) -passthru} |  Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB


fix corrupte mailboxen

Speel wat met

New-MailboxRepairRequest -mailbox eennaam -DetectOnly -CorruptionType SearchFolder, AggregateCounts, ProvisionedFolder, FolderView
Check of mailbox in quarantaine staat
Get-MailboxStatistics identity| Select DisplayName, IsQuarantined | Format-Table -AutoSize

Meer info http://support.microsoft.com/kb/2603736

I pulled the mailbox guid from powershell using

Get-mailbox statistics -identity <user> | fl

I deleted the mailbox guid reg key under: HKLM\SYSTEM\CurrentControlSet\Services\MSExchangeI S\<Server Name>\Private-{db guid}\QuarantinedMailboxes\{mailbox guid}

Restarted the Information Store (first failover all dbs exept the affected on towards other node) and the mailbox came back up.

nieuwe mailbox database
function newdb
{
	$name=read-host "please enter name for database"
	if( (read-host "confirm $name y/n") -eq "y")
	{
		New-MailboxDatabase -Server "mailboxserver"  -Name $name -EdbFilePath "c:\DB\$name\$name.edb" -LogFolderPath "C:\ExchangeLogs\$name\"
		Mount-Database -Identity $name
		Add-MailboxDatabaseCopy -Identity $name -MailboxServer "mailboxserver" -ActivationPreference 2
	}
}
newdb