Convert PowerShell HashTable to CSV File

Unfortunately you can’t use the Export-CSV cmdlet to export a custom HashTable to a CSV file (Not directly) I found you could convert it to a PSObject which can be directly piped to Export-CSV

$OutputTable = $MyHashTable.getEnumerator() | foreach{
    New-Object PSObject -Property ([ordered]@{Computer = $_.Name;Time = $_.Value})
}

$OutputTable | Export-CSV test.csv -NoTypeInformation
...

Continue reading 



Wrapping a Python Windows Service into an EXE Using py2exe

After writing a debugging / dev SMTP server as a Windows Service in Python using pywin32, I decided to figure out how to wrap the Python Windows Service into an EXE so you wouldn’t have to install Python to get it running

I had first attempted to do this in PyInstaller but upon starting the service, Windows would report failure, but the server would still be working. I gave up on PyInstaller and found a solution in py2exe ...

Continue reading 



Python Dummy SMTP Server as a Windows Service

The other day, for debugging purposes, I needed to deploy a dummy SMTP server that would receive, log and NOT send emails. There’s actually a cool little Python one-liner that does something similar to this:

python -m smtpd -n -c DebuggingServer 0.0.0.0:25

Bam. A basic SMTP server that will output messages to stdout. Note that since it’s a port less than 1024, we need to run this command as sudo or in an administrative command prompt in order to bind to port 25

Before I continue, I wan’t to make you aware that I’ve never scripted in Python before. This was my first application (Yeah, screw you, “Hello World”) So I lack experience, and some of my solutions may be inefficient and bad practice. (Please let me know if so!)

For my application, the downside of the previous command is that it only outputs to stdout and does not run as a service (I was looking for more of a permanent solution for debugging / dev purposes… a lot of debugging.)

As a “solution” I wrapped a derivative of this command into a Windows Service using a Python extension called pywin32 ...

Continue reading 



Exchange Management Shell Export vs Delete Date Discrepancy

I discovered something interesting the other day when I was trying to export an Exchange 2010 journaling mailbox to a PST file through the Exchange Management Shell. The -ContentFilter flag for the New-MailboxExportRequest cmdlet does not act the same as the -SearchQuery flag for the Search-Mailbox cmdlet

I would specify the date range of the New-MailboxExportRequest using the ContentFilter flag:

New-MailboxExportRequest -Mailbox exch.journal -ContentFilter "(Received -ge '07/11/2012') -and (Received -le '07/11/2013')" -FilePath "\\SomeServer\SomeFolder\FileName_07112013-07112013.pst"

And then I would delete that date range from the journaling mailbox:

Search-Mailbox -Identity exch.journal -SearchQuery "Received:>=$('07/11/2012') and Received:<=$('07/11/2013')" -DeleteContent

You’d think that I did nothing wrong but I just lost a days worth of my journal ...

Continue reading