Showing posts from April, 2017

CPolydorou.Exchange PowerShell Module

Another one of my PowerShell modules has just been published. This time its the CPolydorou.Exchange module. This module contains cmdlets that have been very useful when dealing with Microsoft Exchange. Let's go through the cmdlets very quickly. Start-ExchangeServerMaintenanceMode Start maintenance mode on an Exchange server. Stop-ExchangeServerMaintenanceMode Stop maintenance mode on an Exchange server. Get-ExchangeServerMaintenanceMode Get the maintenance mode status of an Exchange server. Get-MailboxesPerServer Get the mailbox distribution per mailbox server. Get-MailboxesPerDatabase Get the mailbox distribution per database. Get-RecipientAddress Get the proxy addresses of a recipient. New-RecipientAddress Add a proxy address to a recipient. Remove-RecipientAddress Remove a proxy address from a recipient. Get-OWAUsers Get the number of OWA users. Get-RPCUsers Get the number of RPC users. Get-ActiveSyncUsers Get the number of ActiveSync users.

Windows Server Audit Policy Reset

I run across a very strange issue a few days ago and I feel that I should share it with you since it took me some time to figure it out! Some Exchange servers had stopped recording events in the Security log. The first thing that crossed my mind was to check the latest event in the Security log that would probably be the event regarding the audit policy change. I was correct, there were many events with id 4719 that showed that the policy had been changed. The next step would be to update the policy in order to enable auditing. There were servers that had auditing configured according the security baseline so I backed up the auditing configuration from one of them using the command: auditpol /backup /file:C:\Temp\Audit.txt Next I copied the file to the server with the issue and used the command: auditpol /restore /file:C:\Temp\Audit.txt to restore the settings. The command completed successfully and it was time to check the new auditing settings. For this I used the com

Powershell Strings and Expressions

Today's topic? PowerShell, Strings, Variable Expansion and Quotes! Let's start with the difference between the single and double quotes. When using single quotes, the dollar sign within a string doesn't get treated as a special character so the text following it does not get resolved to the corresponding variable as opposed to the double quotes. The "file" variable in the following examples holds the output object of the Get-Item cmdlet. Variable expansion within strings... Let me start with an example. We have an object that has multiple properties and we want to create a string using the value of one of those properties. We have to use double quotes since we want the variable to be resolved but the result isn't the desired one.   This is because PowerShell will replace the variable with it's string representation and the property will be interpreted as text. This is where the PowerShell expressions come into play. Enclosing the variabl

Microsoft Exchange Protocol Log Size

Although message tracking logs provide a lot of information regarding a message on an Microsoft Exchange infrastructure, there are many times that protocol logs have been proved to be the last resort for detailed information. By default, Exchange has some restrictions on the maximum age or directory size for protocol logs. Although these will fit most of the organizations, I believe that you should check how long back in time your logs are with your currently configured limits and then configure those limits in order to have at least four to five days of logs. The size of a protocol folder depends on the traffic on your server and on the type of the protocol. The receive logs are going to be more than the send logs and the transport logs are going to be more that the frontend transport logs, so pick a number for each of the four folders. The below commands configure the transport and frontend transport service in a way that logs are not deleted until the size of the protocol logs

Counting the objects returned by a PowerShell command

Today I going to write about a little trick I'm using when I want to check the number of objects a PowerShell command returned. If you execute a PowerShell command that returns some kind of objects, you either get a single object or an array of objects. The array object has a property called "Count" that will return the number of items in the array but what if the command returns a single object? Depending on the implementation of the command that returns the objects,  There is no count property on a single object -and if there is, it's probably irrelevant and will result in a bug. Using the logic below you can check if the variable "copies" is an array and if not, create an array with the object in the variable. if ( $copies -isnot [System.Array] ){ $copies = @ ( $copies )} You can also create an array when assigning the result to the variable like: $copies = @ ( Get-ChildItem ) The newer versions of PowerShell will allow you to use the

CPolydorou.7Z Powershell Module

Yet another of my PowerShell modules has been published on the Powershell Gallery. This time it's the CPolydorou.7Z module. This module contains functions to create, extract, test and update and archive along with a function to list it's contents. The supported files are 7z, BZip2, Exe, GZip, Tar and Zip. Let's take a quick look at the functions! New-7ZFile Create a archive from a file or folder and save it to the specified location. You can create an encrypted file, adjust the thread used for the compression and split the archive into multiple files. Get-7ZFile List the contents of an archive. Extract-7ZFile Extract the contents of an archive file to a specified folder. Test-7ZFile Test the integrity of an archive file. Update-7ZFile Update an archive file by adding new items or removing existing ones. Have fun!

Updates on the CPolydorou.PSISE PowerShell Module

A new function has been added to the CPolydorou.PSISE Powershell module named "Remove-PSISETab. This function allows us to remove a Powershell ISE powershell tab using it's name or number, or just the current tab. NAME     Remove-PSISETab     SYNOPSIS     Remove a powershell tab.     SYNTAX     Remove-PSISETab [-Name] <String> [-Force] [<CommonParameters>]         Remove-PSISETab [-Number] <Int32> [-Force] [<CommonParameters>]         Remove-PSISETab [-Current] [-Force] [<CommonParameters>]     DESCRIPTION     Remove a new powershell tab awithin ISE.     PARAMETERS     -Name <String>         The name of the tab.             -Number <Int32>                     -Current [<SwitchParameter>]                     -Force [<SwitchParameter>]             -------------------------- EXAMPLE 1 --------------------------         PS C:\>Remove-PSISETab -Name MyTab         This command will remove the