Scripting Blog

A place to learn about PowerShell and share stories of automation

How Can I Tell if a Folder Has Any Files with a Specific File Extension?

Hey, Scripting Guy! How can I verify whether or not any files with a specific file extension exist in a folder?-- GM Hey, GM. This is actually a pretty easy thing to do. All we have to do is write a WMI query that includes the path of the folder we want to check as well as the file extension we’re checking for. For example, this script ...

How Can I Connect to a Folder When There’s an Apostrophe in the Folder Name?

Hey, Scripting Guy! I’m using the WMI class Win32_Directory to get information about folders on a computer. It works great, except when there’s an apostrophe in the folder name; then, it doesn’t work at all. How can I use WMI to connect to folders that have apostrophes in their names?-- JO Hey, JO. Ah, the apostrophe (also known as ...

Can I Use a Script to Determine the Size of a Folder on a Remote Computer?

Hey, Scripting Guy! Can I use a script to determine the size of a folder on a remote computer?-- SS Hey, SS. Boy, you’d think you’d be able to do that, wouldn’t you? Especially if you’ve glanced through the WMI class Win32_Directory and noticed the property FileSize. Based on that, you might think, “Well, obviously I could just ...

How Can I Get a List of All the Files in a Folder and Its Subfolders?

Hey, Scripting Guy! How can I use a script to show me all the files in a folder? And then how can I modify that script so it shows me all the files in any subfolders of that folder?-- CS Hey, CS. Yesterday we showed everyone a script that changed all the files in a folder from read-only to read-write. We also promised that, in today’s ...

How Can I Determine if a Folder Exists on a Computer?

Hey, Scripting Guy! Is there any way to determine whether or not a specific folder exists on a computer?-- RP, Umatilla, ORHey, RP. There are a couple ways of doing this, depending on whether you are looking for the folder on the local computer or on a remote computer, and depending on whether or not you know the exact path to the folder. ...