As you might imagine, I work on a lot of different files throughout the week. Sometimes it is hard to keep everything straight. I’ll want to return to script I was working on yesterday, but I can’t remember what I called it. So I spend a few minutes searching and filtering until I find it….
Tag: FileSystem
Friday Fun: Creating Sample Files
Not too long ago I came across a PowerShell snippet, probably via Twitter, that showed how to use a few classes from the System.IO namespace to create dummy files. Sadly I forgot the record where I saw this first mentioned. What I liked about the code I saw was the ability to create a dummy…
Friday Fun: The Measure of a Folder
Last week, I demonstrated how to measure a file with PowerShell. This week let’s go a step further and measure a folder. I’m going to continue to use Measure-Object although this time I will need to use it to measure numeric property values. Here’s the complete function after which I’ll point out a few key…
Get Top Level Folder Usage
This is too long to tweet, even written as a one liner. But this will search a folder for top level subfolders and return the file usage for each. [cc lang=”PowerShell”] $folder=”S:\” dir $folder | where {$_.psIscontainer} | foreach { $stat= dir $_.fullname -recurse | Measure-Object -property length -Sum New-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}} [/cc] Again,…
Friday the 13 Script Blocks
In celebration of Friday the 13th and to help ward off any triskaidekaphobia I thought I’d offer up 13 PowerShell scriptblocks. These are scriptblocks that might solve a legitimate business need like finding how long a server has been running to the more mercurial such as how many hours before I can go home. A…
Objects are the answer
As I usually do, I was helping out in the forums at ScriptingAnswers.com. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up…
New File Shortcut
I’ve been looking at the File Server Resource Manager (FSRM) feature in Windows Server 2008 R2 a lot lately. One very nice part of FSRM is the ability to schedule typical file management tasks. One of the examples from the Microsoft storage team is to create a custom task to move old files to another…
Get Disk Quota
During a recent class I was teaching, a student asked about a way to get disk quota reports from Windows file servers. I knew there was a WMI class, Win32_DiskQuota, and had some old VBScript files. However, they were pretty basic and not as robust as I would have liked. So I worked up PowerShell…
All Hail Dir UseALot!
Some of you know my relationship with the a command prompt goes back a long, long way. Naturally I became very adept at using the DIR command, fully taking advantage of its switches to tease out hidden information or to quickly get just the information I wanted. When PowerShell first came out, I made the…
Is That Folder Empty?
In keeping with my recent trend of offering solutions based on PowerShell v2.0, here’s a function I’ve revised to test if a folder is empty. I can’t recall where I used the original function or if I ever did. But I came across it recently and decided to give it a facelift. Manually determining if…