Month: January 2011

Using DropBox to share PowerShell profile scripts across computers

I started using DropBox for several months ago and I love the way it syncs information across several computer I own. I put all the scripts under development in a DropBox folder and work on them from any PC I have access to. And, the changes are always there on all PCs. There is versioning too. This is simply awesome. Apart from the usual stuff like sharing documents, scripts, and photos, I also use DropBox to share my PowerShell profile scripts across all these computers I work on. All this is done automatically. I just need to set it up once and all my computers receive the changes to my profile script almost instantly. This is how I have been doing it: First, I have DropBox setup on all my computers. Second, I created a folder within DropBox folder and called it PowerShellProfiles. After this, I copied all my PowerShell profile scripts to the PowerShellProfiles folder on DropBox. BTW, I use two different profiles. One for PowerShell console/PowerGUI and another just for ISE. This is …

Monitoring file creation using WMI and PowerEvents module

There are several ways we can create a file monitoring script using PowerShell. There is also a cmdlet in PowerShellPack called Start-FileSystemWatcher to monitor file /folder changes. However, none of these methods survive a exit at the console or wherever the script is running. This is because all these methods create a temporary event consumer. As I’d mentioned in an earlier post, Trevor’s PowerEvents module makes it very easy to create permanent event consumers in PowerShell. In today’s post, we shall look at how we can do that. Before we dig into that, let us first see how we can create a file monitoring script using PowerShell. Many people use CIM_DirectoryContainsFile class and create an event listener. This is how we use do that class in PowerShell.

As you see in the above output, what we get as a part of event data is just that string contained in $Event.SourceEventArgs.NewEvent.TargetInstance.PartComponent. Of course, if you are RegEx lover, you’d just parse that and find the name (extension, etc) of the new file that just got …