The GlobalFunctions PowerShell module has been updated to support writing of log messages to the PowerShell output pipeline.
When writing to the PowerShell output pipeline, the severity level is not written to the pipeline. In most cases you will use this option for debugging purposes.
# Import module first Import-Module -Name GlobalFunctions # Create an instance of the logger $ScriptDir = Split-Path -Path $script:MyInvocation.MyCommand.Path $ScriptName = $MyInvocation.MyCommand.Name $logger = New-Logger -ScriptRoot $ScriptDir -ScriptName $ScriptName -LogFileRetention 14 # Write an informational message to the log file only $logger.Write('Some informational message') # Write an informational message to the log file only $logger.Write('Some message to log and console',0,$true) # Write a warning level message to log file and the message only to PowerShell output pipeline $logger.Write('Some warning message',2,$true)
Remember to add the severity level when writing to console.
Read more about the GlobalFunctions module here.
You can get the source code here:
The PowerShell module GlobalFunctions got updated to Version 2.0. This module is used by some of my PowerShell scripts which utilize centralized logging.
The new release contains the first functions required for some upcoming scripts for managing on-boarding process for joiners and the off-boarding process for leavers for companies utilizing Office 365.
The New-RandomPassword functions is based on Simon Wahlin's script published here: https://gallery.technet.microsoft.com/scriptcenter/Generate-a-random-and-5c879ed5
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
The Exchange Server product used the Extensible Storage Engine (ESE, aka JET Blue) to store data for decades. The story of the JET Blue (in contrast to JET Red which is used for Access database) can be read here (https://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine). In the acient days of data storage the ESE database was the best choice for storing mostly unstructured data with many dynamic properties.
The Messaging API (MAPI) had been developed in the 1990s to provide programmers with a set of unified interface for easier message exchange. The MAPI documentation at TechNet has been replaced by the current Outlook 2013 MAPI Reference. In todays world it is not easy to find reliable ressource about the original MAPI implementation. The only printed resource is Inside Mapi (Microsoft Programming Series) , ISBN 978-1572313125 , which has been published in 1996.
At Ignite 2015 Ross Smith VI joked about moving the Exchange storage engine to SQL. Back in the day with Exchange 2013 in production and Exchange 2016 coming, this was true. But Ross laid the tracks for the evolution of Exchange.
But it seems that the Exchange Product Team realized that in today's world with heavily standardized communication and less dynamic requirements than in the 1990s the days of JET blue are over. At the same time SQL Server evolved to mature database solution, capable of handling big data. The question was, if it can store SharePoint data, why not Exchange data. After twenty years of Exchange Server using the good ole ESE engine it was time to move on.
The SQL scripts that are used by Exchange to configure SQL are loacted in $exbin\SQL
CREATE TABLE [dbo].[MAPI_PROPERTIES]( [MAPI_PROPERTTY_ID] [int] IDENTITY(1,1) NOT NULL, [MAPI_PROPERTY_NAME] [nchar](127) NOT NULL, [IsWellKnownProperty] [bit] NOT NULL, [MAPI_TYPE_ID] [int] NOT NULL, CONSTRAINT [PK_MAPI_PROPERTIES] PRIMARY KEY CLUSTERED ( [MAPI_PROPERTTY_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[MAPI_PROPERTIES] WITH CHECK ADD CONSTRAINT [FK_MAPI_PROPERTIES_MAPI_TYPES] FOREIGN KEY([MAPI_TYPE_ID]) REFERENCES [dbo].[MAPI_TYPES] ([MAPI_TYPE_ID]) GO ALTER TABLE [dbo].[MAPI_PROPERTIES] CHECK CONSTRAINT [FK_MAPI_PROPERTIES_MAPI_TYPES] GO
The current Exchange 2016 CU2 Preview supports an undocumented registry key to activate SQL Server support for Exchange. Personally I do not know, if this was supposed to be officially included in a public realease. So maybe the SQL support was made available by error and is already removed from the most current build again.
The famous SqueakyLobster registry key in has been used in Exchange 5.5 to troubleshoot performance issues. The new "Lobster" key is used to activate hidden code in Exchange Server product. The name of the key is LobsterMapiDB.
This key activates support for Exchange modern storage. Without this key you won't be able to move mailboxes from ESE legacy storage to SQL modern storage.
It is assumed that a SQL Server 2014 instance is available. A SQL Server 2014 Express edition is sufficient for testing purposes.
Note: Any changes to configurations or the registry should be validated in a test environment first. Never try this in production right away.
The high level steps required to activate SQL support for Exchange 2016 are:
The detailed steps are:
<?xml version="1.0" encoding="utf-8" ?> <!-- Exchange SQL Configuration - preliminary support --> <!-- %MAILBOXDATABASENAME% will be replaced by Exchange --> <!-- More information https://goo.gl/QiTtDo --> <configuration> <sectionGroup name="SqlMapiProviderGroup" type="Microsoft.Exchange.Data.SQL.SqlMapiProviderGroup, Microsoft.Exchange.Data.Common, Version=15.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <section name="SqlMapiProviderSection" type="Microsoft.Exchange.Data.SQL.SqlMapiProviderGroup, Microsoft.Exchange.Data.Common, Version=15.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </sectionGroup> <runtime> <gcServer enabled="True" /> <generatePublisherEvidence="False" /> </runtime> <appSettings> <add key="MigrateMailboxesAutomatically" value="false" /> <!-- Not yet supported --> <add key="AllowJETBlueCoexistence" value="true" /> <!-- Allows for SQL/ESE Coexistence in DAG --> <add key="PerDatabaseMaxSize" value="1GB" /> <add key="VerboseLoggingEnabled" value="False" /> </appSettings> <SqlMapiProviderSection> <SqlMapiProvider> <add name="LobsterMapiDB" providerName="System.Data.SqlClient" connectionString="Data Source=SERVERNAME\INSTANCE;Initial Catalog=%MAILBOXDATABASENAME%;Integrated Security=True;MultipleActiveResultSets=True" /> </SqlMapiProvider> </SqlMapiProviderSection> </configuration>
CREATE LOGIN [DOMAIN\Exchange Trusted Subsystem] FROM WINDOWS
More can be found here:
Enjoy Exchange for the next 20 years...
The PowerShell script to purge Exchange Server and IIS log files has been updated to version 2.1.
The function Copy-LogFiles has been slightly rewritten and there has been a change in the cmdlet parameters.
When using ArchiveMode CopyAndZip or CopyZipAndDelete all copied log files in the EXCHANGESERVER\LOGS folder are added to a compressed archive. The script creates a separate archive for IIS and Exchange logs.
Code updated
function Copy-LogFiles { [CmdletBinding()] param( [string]$SourceServer, [string]$SourcePath, $FilesToMove, [string]$ArchivePrefix = '' ) if($SourceServer -ne '') { # path per SERVER for zipped archives $ServerRepositoryPath = Join-Path -Path $RepositoryRootPath -ChildPath $SourceServer # subfolder used as target for copying source folders and files $ServerRepositoryLogsPath = Join-Path -Path $ServerRepositoryPath -ChildPath $LogSubfolderName $ServerRepositoryPath = Join-Path -Path $RepositoryRootPath -ChildPath $SourceServer if(!(Test-Path -Path $ServerRepositoryPath)) { # Create new target directory for server, if does not exist $null = New-Item -Path $ServerRepositoryPath -ItemType Directory -Force -Confirm:$false } foreach ($File in $FilesToMove) { # target directory $targetDir = $File.DirectoryName.Replace($TargetServerFolder, $ServerRepositoryLogsPath) # target file path $targetFile = $File.FullName.Replace($TargetServerFolder, $ServerRepositoryLogsPath) # create target directory, if not exists if(!(Test-Path -Path $targetDir)) {$null = mkdir -Path $targetDir} # copy file to target $null = Copy-Item -Path $File.FullName -Destination $targetFile -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue } if($ZipArchive) { # zip copied log files $Archive = Join-Path -Path $ServerRepositoryPath -ChildPath ('{0}-{1}' -f $ArchivePrefix, $ArchiveFileName) $logger.Write(('Zip copied files to {0}' -f $ArchiveFileName)) # delete archive file, if already exists if(Test-Path -Path $Archive) {Remove-Item -Path $Archive -Force -Confirm:$false} try { # create zipped asrchive Add-Type -AssemblyName 'System.IO.Compression.FileSystem' [IO.Compression.ZipFile]::CreateFromDirectory($ServerRepositoryLogsPath,$Archive) } catch { $logger.Write(('Error compressing files from {0} to {1}' -f $ServerRepositoryLogsPath, $Archive),3) } finally { # cleanup, if compression was successful if($DeleteZippedFiles) { $logger.Write(('Deleting folder {0}' -f $ServerRepositoryLogsPath)) $null = Remove-Item -Path $ServerRepositoryLogsPath -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue } } } } }
The PowerShell script to purge Exchange Server and IIS log files has been updated to version 2.0.
Release 2.0 allows for copying of files that will be deleted to be copied to a central file repository. The script will create a folder per server and the full log file folder structure will be preserved.
The next release will contain an option to compress the copied log files.
Added code:
function Copy-LogFiles { [CmdletBinding()] param( [string]$SourceServer, [string]$SourcePath, $FilesToMove ) if($SourceServer -ne '') { # path per SERVER for zipped archives $ServerRepositoryPath = Join-Path -Path $RepositoryRootPath -ChildPath $SourceServer # subfolder used as target for copying source folders and files $ServerRepositoryLogsPath = Join-Path -Path $ServerRepositoryPath -ChildPath $LogSubfolderName $ServerRepositoryPath = Join-Path -Path $RepositoryRootPath -ChildPath $SourceServer if(!(Test-Path -Path $ServerRepositoryPath)) { # Create new target directory for server, if does not exist $null = New-Item -Path $ServerRepositoryPath -ItemType Directory -Force -Confirm:$false } foreach ($File in $FilesToMove) { # target directory $targetDir = $File.DirectoryName.Replace($TargetServerFolder, $ServerRepositoryLogsPath) # target file path $targetFile = $File.FullName.Replace($TargetServerFolder, $ServerRepositoryLogsPath) # create target directory, if not exists if(!(Test-Path -Path $targetDir)) {$null = mkdir -Path $targetDir} # copy file to target $null = Copy-Item -Path $File.FullName -Destination $targetFile -Recurse -Force -Confirm:$false -ErrorAction SilentlyContinue }-Force if($ZipArchive) { # zip copied log files # <# NOT FULLY TESTED YET $Archive = Join-Path -Path $ServerRepositoryPath -ChildPath $ArchiveFileName $logger.Write(('Zip copied files to {0}' -f $ArchiveFileName)) if(Test-Path -Path $Archive) {Remove-Item $Archive -Force -Confirm:$false} Add-Type -AssemblyName 'System.IO.Compression.FileSystem' [IO.Compression.ZipFile]::CreateFromDirectory($ServerRepositoryLogsPath,$Archive) #> } } }
The PowerShell script to create a new room mailbox has been updated to Version 1.1.
The new release supports adding of a phone number to the room details. Issue #2 is now closed.
Creating a separate security group for calendar booking is still open as issue #1.
You can read the original and up-to-date blog post here: Create a new room mailbox with security groups