Monitoring for Undelivered UM voicemail with PowerShell

Just a quick one.

My coworker approached me looking for an easy way to see if there are any files in a given directory whose last modified time is older than a minute or two. Apparently, he has had some issues with voicemails being stuck in the queue and never being properly delivered.

I quickly threw this together and used it as an opportunity to discuss the difference between setting up a foreach loop and piping to foreach-object. It was also a good time to introduce the % and ? aliases, which are for foreach-object and where-object respectively.

As you may know, piping to foreach-object will send objects down the pipeline as they become available. Whereas as one would generally collect all the objects prior to entering a foreach loop. While this difference may not make an appreciable difference with a small number of objects, it can make a big difference in resource utilization with larger collections of objects.

Here’s the code:

$date = get-date

$path = “C:\temp”

get-childitem -path $path | ?{-not $_.psiscontainer} | %{If (($date – $_.LastWriteTime).totalminutes -gt 1) {DO SOMETHING}}




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s