Weekend Scripter: Use PowerShell and Pinvoke to Remove Stubborn Files

Summary: Windows PowerShell MVP, Boe Prox, talks about using Windows PowerShell and Pinvoke to delete locked files. Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest blog post by newly crowned Windows PowerShell MVP, Boe Prox. Long-time readers of the Hey, Scripting Guy! Blog are familiar with Boe’s work, but this is his…


How Can I Copy Selected Columns From a CSV File to an Excel File?

Hey, Scripting Guy! How can I copy selected columns from a CSV file to an Excel file?– MdP Hey, MdP. One thing that people always worry about (and rightly so) is that one of these days the Scripting Guys will do something that tears a hole in the space-time continuum. Some of you might be…

1

How Can I Convert a Tilde-Delimited File to Microsoft Excel Format?

Hey, Scripting Guy! How can I convert a tilde-delimited file to Microsoft Excel format?– JN Hey, JN. You know, to tell you the truth we’re beginning to rethink our approach to this column. After all, usually we tell people how easy things are, and how – without much effort – they can write a script…

3

How Can I Extract Information Located Between Two Known Values in a Text File?

Hey, Scripting Guy! In a text file, how can I extract the information that appears between the string HOSTNAME= and a blank space?– B Hey, B. You’ll have to pardon us if we seem a little sluggish today; we’re still recovering from all the fun and excitement of Windows PowerShell Week. What if you missed…

4

How Can I Clear the Contents of Any File Dropped on My Script Icon?

Hey, Scripting Guy! How can I write a script that will clear the contents of any file that I drag and drop on the script icon?– SN Hey, SN. Say, you didn’t by any chance misplace a few hundred thousand insects did you? OK; just thought we’d ask. This past weekend the Scripting Guy who…

0

How Can I Remove Double Double Quotes From a Text File?

Hey, Scripting Guy! I have a comma-separated values file that has data similar to this: data1″,””data2″”,”data3″,””data4″”. As you can see, some of the items are enclosed by two sets of double quote marks (like “”data2″”). How can I remove one of those sets of double quote marks, leaving the item looking like this: “data2”?– RH…

2

How Can I Move the Oldest File in a Folder to a Different Folder?

Hey, Scripting Guy! How can I move the oldest file in the folder C:\Upload to C:\Download?– DD Hey, DD. Funny you should mention the word “oldest.” The Scripting Guy who writes this column recently attended a family reunion and, for the first time ever, came face-to-face with the whole idea of getting old. This Scripting…

2

How Can I Get a Script to Delete Itself?

Hey, Scripting Guy! I have a script for installing a printer that I give to my end users. When the script finishes, I’d like it to be able to delete itself. How can I get a script to delete itself?– EA Hey, EA. You know, that’s an interesting idea: disposable scripts, just like disposable razors…

1