Powershell Needful Things put that in your pipeline

20Apr/170

Display the last couple of lines in the crawler log

Posted by Jean Louw

From time to time you need to rebuild an Exchange server database search catalog, and you can monitor the progress using performance monitor. However, I have found it more useful to monitor the actual crawler log, and see which mailbox it is currently busy crawling.

The following script will display the last 25 lines of the last crawl log and refresh it every 15 seconds. This assumes you have Exchange installed in the default location. If not, you just need to update the path.

while (1 -eq 1)
{
cls
import-csv (dir 'C:\Program Files\Microsoft\Exchange Server\V15\Logging\Search\Crawler' | sort -Descending | select -First 1).fullname -Header date-time,component,version,operationId,databaseName,mailboxGuid,operation | select -last 25 | ft -AutoSize
sleep 15
}

2017-04-20_09-36-13

If you find this, I hope it can help you in your efforts to rebuild a corrupt search catalog.

1Mar/170

Quickly find all deferred messages in Exchange

Posted by Jean Louw

Here is a quick little one liner to find all the deferred messages with FromAddress, Recipients and DeferReason.

Get-TransportServer | Get-Queue | ?{$_.Identity -like '*submission*'} | get-message -IncludeRecipientInfo | ?{$_.Status -eq 'Retry'} | select FromAddress,Recipients, DeferReason

2017-03-01_14-21-56

I'm working now on a function to resolve ambigious recipients and loops from here if possible.

21Oct/163

Exchange 2013 Audit Script

Posted by Jean Louw

I finally had time to finish the last little issues with this script.

As with the Exchange 2010 script, this script can be used to audit various aspects of Exchange servers in the organization. Some administrators may deploy it as a morning check script, to check the health of the environment, while others may use it at client sites, as a quick overview of the server health.

Features:

- Audit Exchange 2013 servers including all features of the Exchange 2010 script.
- Added DAG health (get-mailboxdatabasecopystatus).
- Added certificates check to alert about expiring certificates.
- Colour coded some of the alerts to make them more visual.
- Updated the script output to a more Exchange 2013 look and feel.
- Added a check for the CU version of Exchange.
- Reduced the Event Log checks to 4 hours to increase speed, and reduce output size.

I have decided to make this script a GitHub project, so that anyone with PowerShell / Exchange knowledge can contribute to the project.

This script is a project I maintain in my free time, and which I provide to the community at no cost. If you like this script and use it in production, please help me keep this project free by considering a small donation.

The latest version of the script can be downloaded at https://github.com/technologicza/testexchange2013

30Sep/160

Exchange 2013 Audit Script

Posted by Jean Louw

It has been a long time since I have posted anything on this blog, and with good reason. I started my own company a while ago, and it has consumed most of my time for the last couple of years.

I know that Exchange 2013 is something of the past, but I also know that it is very much still deployed in many organisations. Many of the subscribers to the blog have asked for an Exchange 2013 version of the script, and I have finally decided to sit down and complete it.

It will be available for download soon, so for now, please see below a screenshot of the result file.

Exchange 2013 Audit Report

3Jan/1311

Bulk Export Exchange Calendar data to Excel

Posted by Jean Louw

2013-01-03_09-45-01

The previous version of this script, proved far more popular than I could have ever imagined. It was however very complex, which caused numerous failures during execution.

I have recently spent some time streamlining the script at a client, to a point where it is now running fully automated on a schedule.

The new script has the following requirements:

  • The script assumes that it is running in C:\Scripts\CalX - if this path is not possible you have to manually update the script to reflect the location.
  • The script should be executed in the Exchange 20xx management shell.
  • The script requires that Outlook 2007 or above is installed on the computer.
  • The script requires texprof.exe to create the profiles.
  • The script requires MAPILab Advanced Outlook Security to control the security popups.
  • The script requires a file called rooms.txt in the same folder that the script is executed from.

If any exported calendar CSV data files exist from a prior runs, the script will backup these files. The script runs thought each room, in the rooms.txt file and creates / updates a profile on the local machine.  The script assigns full mailbox permissions to the current user, for the calendar to be exported. The script logs onto Outlook using that profile, and exports the calendar data to a CSV.

When it is complete, it combines all of the calendar export files into a single CSV containing all the exported data. As always, your comments and suggestions are always welcome.

The script and texprof.exe can be downloaded below:

20May/118

Exchange 2010 stale & unused mailbox cleanup tool

Posted by Jean Louw

I have finally completed the testing of the User Mailbox Cleanup tool for Exchange 2010.

Although this script is run from the EMS, it opens as a GUI utility which Exchange Administrators can use to cleanup stale or old Exchange mailboxes from Exchange 2010 mailbox servers.
The utility has a couple of preset search queries to help locate stale or old mailboxes, and once complete, administrators have various options they can use to remove or cleanup these mailboxes.

The script obviously does not care about the significance of the individual mailboxes, although certain system mailboxes are excluded from the search. You still have to verify your selection before you take action against any items.

The script can be downloaded for free from here:

http://www.powershellneedfulthings.com/?page_id=291

Your comments and feedback with regards to these items are always welcome.

13May/110

Monitor the number of items in a list of Public Folders

Posted by Jean Louw

You can use the following basic code, to monitor the number of items in a list of public folders.

My client has a number of workflow processes which rely on public folders, and sometimes if a process stops, the number of items in the public folder will increase. In this script, you can specify the subfolder name, in the root folder and all the folders in that folder will be listed, with the number of items in each.

Replace "folder name" with the name of you main folder that you wish to monitor.

This code uses Outlook to logon and read the folder information, so the account that you are logged onto Outlook with, requires atleast read permission in the public folders which you are monitoring.

$pf = "folder name"
$itemCount = @{Name="Count";expression={foreach-object {($pfroot.folders.Item($pf).folders.item($_.Name).items).count}}}
$pfroot = (new-object -com outlook.application).getNamespace("MAPI").Session.GetDefaultFolder(18)
$pfroot.folders.Item($pf).folders | select Name, $itemCount
Filed under: exchange No Comments
13May/112

Exchange 2010 Cleanup Utility

Posted by Jean Louw

Good news!

I have completed the update of the Exchange mailbox cleanup tool, for use with Exchange 2010.

I don't have access to a 2010 server at the moment to finalise testing.

I should be able to complete testing next week, and post the updated utility to the site.

Filed under: cleanup, exchange 2 Comments
10May/114

Find SAMAccountName with trailing space

Posted by Jean Louw

The other day, one of the security guys at a customer had a problem with a reporting package which needs to import objects from Active Directory via LDAP.

The process appeared to import a limited amount of user accounts and then stop.

Feedback provided by the vendor, stated that we had duplicate SAMAccountNames in the domain, which as you know is impossible.

I started investigating the issue, and found a number of objects which, at first appeared to have duplicate SAMAccountName properties. On further investigation, I found that some of these duplicates, were indeed similar, but ended in a trailing space.

I tested this, and it seemed that the ADUC does not allow you to create objects with trailing spaces, so these objects may have been imported from other directories, or old NT4 migrations etc.

I needed a way to find all the objects with trailing spaces in the SAMAccountName property to send the list to the administrators to fix, as this involved some human interaction which I am unable to script.

This seemed easy at first, once you realise that not all SAMAccountName properties are the same length!

The following script will use the Exchange Get-User cmdlet to determine the length of the SAMAccontName property, and then inspect the last character in the string to see if it is a space. If it is, it is added to a variable and reported at the end.

Hopefully this script saves you some time.

$broken = @{Name="Broken";expression={foreach-object {($_.SAMAccountName).ToString().SubString((($_.SAMAccountName.ToString().Length)-1),1).Contains(' ')}}}

$users = Get-User -Resultsize Unlimited

Foreach ($user in $users){
If (($user | Select $broken).broken -eq $True){
[array]$brokenAccounts += $user}
}

$brokenAccounts | Select Name, SAMAccountName, $broken
4Feb/110

Updated: Exchange 2010 Audit Script

Posted by Jean Louw

I have made some updates to the script:

  • Fixed the pipeline issue – You can now use commands like Get-ExchangeServer and pipe that to the script to build a server selection.
  • Embedded the header image into the HTML – This now allows you to display the image even if the server is not connected to the Internet.
  • Changed logical disk information to volume information – This will include volume mount points.
  • Database whitespace – the mailbox database report now displays the whitespace for each database.
  • Move Requests – I have added the ability to display uncleared move requests. This however will currently display on the report for any mailbox server.
  • The version number now correctly displays as 1.1 instead of 4.

Some items I still need to fix:

  • HTML / javascript error with single file report.
  • Colour on the move request section.
  • DAG information and mailbox count by server.
  • Display move requests from current server only.

If you have any additional requests for items you would like to see in the script, or even of you feel the colour scheme is horrible, please let me know.

More complete information, and the download link for the script can be found here:
http://www.powershellneedfulthings.com/?page_id=281