PowerShell Scripts

edit this page

Achtung: Diese Scripts sind Beispiele, sie sind nicht für die Verwendung in Produktivsystemen gedacht! Die Autoren von ntSystems.it können keine Haftung für eventuelle Schäden durch diese Scripts übernehmen.

 

Exchange: Set SimpleDisplayName on all Mailboxes where this Attribute is empty; change characters like ö to oe; send E-Mail if script fails

   1: Import-Module 'C:\Users\daniel nitz\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\ex2k10.domain.local\ex2k10.domain.local.psm1'
   2:  
   3: $Mailboxes = get-Mailbox | where {$_.SimpleDisplayName -eq ""}
   4: if($Mailboxes -ne $null)
   5: {
   6:     try {
   7:         ForEach ($Mailbox in $Mailboxes)
   8:         {
   9:             $NameString = $Mailbox.Name
  10:             if($NameString -match "ü")
  11:                 {
  12:                 $NameString = ($NameString -replace "ü","ue")
  13:                 }
  14:             if($NameString -match "ä")
  15:                 {
  16:                 $NameString = ($NameString -replace "ä","ae")
  17:                 }
  18:             if($NameString -match "ö")
  19:                 {
  20:                 $NameString = ($NameString -replace "ö","oe")
  21:                 }
  22:             Set-Mailbox -Identity $Mailbox.Name -SimpleDisplayName ($NameString + " - COMPANY")
  23:         }
  24:     } Catch {
  25:         Send-MailMessage -to daniel.nitz@domain.local -Subject "Exchange Shell Script Error" -from ex2k10@domain.local -SmtpServer ex2k10.domain.local
  26:     }               
  27: }
  28:     

 

Exchange: Set Out of Office Assistent on Mailboxes where the “Office” property isn´t empty

   1: Import-Module 'C:\Users\daniel nitz\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\ex2k10.domain.local\ex2k10.domain.local.psm1'
   2:  
   3: $Mailboxes = get-Mailbox | where {$_.Office -ne ""}
   4: try {
   5:     $OOFTextExternal = ${E:\OOF-Text\External-Text.txt}
   6:     $OOFTextInternal = ${E:\OOF-Text\Internal-Text.txt}
   7:     
   8:     ForEach ($Mailbox in $Mailboxes)
   9:     {
  10:         Set-MailboxAutoReplyConfiguration -Identity $Mailbox.Name -AutoReplyState scheduled -StartTime "2011.01.21T07:00" -EndTime "2011.01.21T19:00" -ExternalAudience All -ExternalMessage $OOFTextExternal -InternalMessage $OOFTextInternal   
  11:     }
  12: } Catch { Send-MailMessage -to daniel.nitz@domain.local -Subject "Exchange Shell Script Error" -from ex2k10@domain.local -SmtpServer ex2k10.domain.local
  13: }