PowerShell: Remembering PowerShell Module Names

This is a small and simple post. I don’t know about you, but I am always forgetting the correct wording of a PowerShell Module that I need to import before I can start typing away the PowerShell cmd-lets I am trying to use. So, instead, I remember this:

Get-Module -ListAvailable

Doing this shows me the available modules and I can then enter the Import-Module command I am after, instead of trying to guess what the Module Name was.

Until next time!

Advertisement

Exchange PowerShell: Find Mailbox with Specific Email Address

Every now and then I get asked to find the mailbox that an email has been sent to with only an email address to go off. Thankfully, PowerSshell makes this very easy to find the owner straight away.

Get-Mailbox | Where {$_.emailaddresses -like "smtp:phil@ctrlf5.me"} | FT Name,Alias

All you need to do is change the email address from phil@ctrlf5.me to the email address you are trying to find. The FT Name,Alias just shows me the information I need to see, but you are welcome to change that to suit your needs.

Until Next Time!

PowerShell Script: Delete Files Older Than 7 Days

Another file operations PowerShell script that was recently required. This time we had a folder that contains a large number of log files that were never rotated and took up a large amount of disk space. These logs are only used for troubleshooting issues if they occur and it is rarely required for us to go over log files older than 7 days, so why are we keeping the rest?

Here is an easy one liner to help!

Until next time!

Get-ChildItem –Path “E:\TEMP\Logs” –Recurse | Where-Object{$_.LastWriteTime –lt (Get-Date).AddDays(-7)} | Remove-Item

Powershell: Get-Date (in the future)

Today I needed to know what date it would be 400 days from now. Since I do not have 400 fingers to work that out or the time to count out 400 days on a calendar, I started up Windows Powershell and used it to tell me the date 400 days from now.

(Get-Date).AddDays(400)

Simple! The answer returned was Thursday, 17 July 2014. Powershell never ceases to amaze me 🙂

Until next time!