PowerShell module providing centralizied logging and other helpful functions.
Import-Module GlobalFunctions $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path $ScriptName = $MyInvocation.MyCommand.Name # Create a new logger object, keeping the last 14 days of log files $logger = New-Logger -ScriptRoot $ScriptDir -ScriptName $ScriptName -LogFileRetention 14 # Write a new informational message to the log file $logger.Write('My Log Message') # Write an error message to the log file $logger.Write('My custom error message') # Write a warning message to the log file $logger.Write('My custom warning') # Send a log file by email at the end of your script $logger.SendLogFile('sender@mcsmemail.de', 'recipient@mcsmemail.de', 'smtpserver.mcsmemail.de')
You can "install" a PowerShell module by copying the module to a sub folder of the same name as the module in either of the two following locations:
PS C:\> $env:PSModulePath C:\Users\admin\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\sys tem32\WindowsPowerShell\v1.0\Modules
Create a new folder named GlobalFunctions in C:\Program Files\WindowsPowerShell\Modules
Copy the GlobalFunctions.psm1 file to C:\Program Files\WindowsPowerShell\Modules\GlobalFunctions
That's it.
These steps assume that you use a dedicated PowerShell scripts folder, e.g. D:\MyScripts
.\Set-PersistentPSModulePath.ps1 -Add
Close the current PowerShell window and open a new PowerShell window. That's it.
When using PowerShell 5, you can simply use the following PowerShell command from within an administrative PowerShell window.
Install-Module GlobalFunctions
When a new version of the GlobalFunctions module has been released, use the following PowerShell command to update the module.
Update-Module GlobalFunctions
This script copies a single receive connector from a source Exchange Server to a single target Exchange server or to all other Exchange servers.
The primary purposes of this script are:
Copy Exchange 2013/2016 receive connector nikos-one-RC2 from server MBX01 to server MBX2
.\Copy-ReceiveConnector.ps1 -SourceServer MBX01 -ConnectorName nikos-one-RC2 ` -TargetServer MBX2 -DomainController MYDC1.mcsmemail.de
Copy Exchange 2013/2016 receive connector nikos-one-RC2 from server MBX01 to all other Exchange 2013 servers
.\Copy-ReceiveConnector.ps1 -SourceServer MBX01 -ConnectorName nikos-one-RC1 ` -CopyToAllOther -DomainController MYDC1.mcsmemail.de
Copy Exchange 2013/2016 receive connector nikos-two relay from Exchange 2007 server MBX2007 to Exchange 2013 server MBX01 and reset network bindings
.\Copy-ReceiveConnector.ps1 -SourceServer MBX2007 -ConnectorName "nikos-two relay" ` -TargetServer MBX01 -MoveToFrontend -ResetBindings ` -DomainController MYDC1.mcsmemail.de
Additional credits go to Jeffery Land, https://jefferyland.wordpress.com
The PowerShell script to purge IIS and Exchange Server 2013 has been updated to support email reporting.
When executed by a scheduled task it is extremely helpful to Exchange Administrators to receive some sort of conformation of the script execution.
If using the SendMail switch, a summary report is sent as an Html email
Parameters added:
.PARAMETER SendMail Switch to send an Html report .PARAMETER MailFrom Email address of report sender .PARAMETER MailTo Email address of report recipient .PARAMETER MailServer SMTP Server for email report
This post has first been posted on my legacy blog.
This script adds a new scheduled task for an Exchange Server 2013 environment in a new task scheduler group "Exchange".
When providing a username and password the scheduled task will be configured to "Run whether user is logged on or not".
When username and password are provided the Register-ScheduledTask cmdlet verfies the logon credentials and will fails, if the credentials provided (username/password) are not valid.
Note: The cmdlet Register-ScheduledTask consumes the user password in clear text.
# EXAMPLE # Create a new scheduled task using a dedicated service account .\New-ScheduledExchangeTask.ps1 -TaskName "My Task" -ScriptName TaskScript1.ps1 -ScriptPath D:\Automation -TaskUser DOMAIN\ServiceAccount -Password P@ssw0rd # EXAMPLE # Create a simple scheduled task .\New-ScheduledExchangeTask.ps1 -TaskName "My Task" -ScriptName TaskScript1.ps1 -ScriptPath D:\Automation
This script removes/disables HealthMailboxes that show an inconsistent error when querying monitoring mailboxes using
Get-Mailbox -Monitoring
and receiving a warning like
"WARNING: The object DOMAINNAME/Microsoft Exchange System Objects/Monitoring Mailboxes/Health_Mailbox_GUID has been corrupted,
# Remove the HealthMailbox(es) having an empty database attribute .\Fix-HealthMailboxes.ps1 -Remove