Scripting Blog

A place to learn about PowerShell and share stories of automation

Hey, Scripting Guy! How Can I Delete All the Files in a Folder Except for the Most-Recently Created File?

Hey, Scripting Guy! I have a folder that has about 50 files in it. How can I delete all those files except the one most-recently created?-- GA Hey, GA. You know, today would be a good day to review some of the items that have recently been in the news. (You know that life must be exceedingly dull for the Scripting Guy who writes this column...

Hey, Scripting Guy! How Can I Search a Text File for Activities That Took Place on a Specified Date?

Hey, Scripting Guy! I’m trying to write a script that can go through a log file and determine the number of users who logged off on a particular day. Can you help me?-- TM Hey, TM. You know, when you work at Microsoft people think you probably come to work in your pajamas, ride a unicycle through the hallways, and do all those other weird...

Hey, Scripting Guy! How Can I Move Emails From One Outlook Folder to Another?

Hey, Scripting Guy! You’ve had several articles that show how it’s possible to find specific email messages in Outlook; for example, you’ve shown us how to find all the emails sent by a particular person. What I was wondering is this: after you find these emails, is it possible to have the script move the messages to a different folder...

Hey, Scripting Guy! How Can I Determine the Distinguished Name of the OU Where the Logged-On User’s User Account Resides?

Hey, Scripting Guy! As part of a logon script, I need to determine the distinguished name of the OU for the user logging on. How can I do that?-- LK Hey, LK. Today is May 12th, which might not mean much to you. But, then again, maybe it does; after all, May 12this the birthday of Cosimo II de' Medici, Grand Duke of Tuscany, born May 12, 1590...

Hey, Scripting Guy! How Can I Use Windows PowerShell to Pick Out the Unique File Extensions Used in a Collection of Files?

Hey, Scripting Guy! I’m having a strange problem with Windows PowerShell, and I was wondering if you could help me solve it. I’m trying to get a list of the unique file extensions used by the files in a folder. I have a whole bunch of different file types in that folder, but every time I run my command it returns just one file extension...