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 …

PowerShell ISE addon menu generator

This is yet another ISE addon I have been using for quite sometime. I polished it a bit so that I can share it here with you all. This addon lets you create addon menu items easily. Without this, I used to open up my ISE profile script and add the menu items manually myself. This is how the addon looks: Here is the script behind this addon.

I used WinForms (shame on me, I did not use WPF) for the GUI. If you want to use this, this is what you need to do: Copy the contents of above script to a .ps1 file Dot source this .ps1 in your profile script for ISE Add the following code to the next line

Once you are done, close and re-open ISE. This is what you will find in the addons menu: Now, you can add menu items using the GUI. The “Script block” textbox supports Return and Tab keys. So, you can align the script block as you wish. Finally, if you select …

Microsoft Technet Webcast: Manage your Hyper-V environment with PowerShell

I just finished my Technet webcast session on Managing Hyper-V Environment with PowerShell. The session recording will be available soon for offline viewing. Here are the slides I used for this session and the scripts used for the demos. Here are the demo scripts for download.   This webcast is now avaiilable for offline viewing and download @ I will be presenting a Technet webcast on “Managing Microsoft Hyper-V environment with PowerShell” on January 28th. This is scheduled to start at 1600hrs IST and will be live for 90 minutes. Do register if you are interested. This will be available on-demand post the event.

Enable-AutoAdminLogon: PowerShell to enable auto admin logon on local and remote systems

I have been working on quite a few utility scripts for my test bed automation. This is just one of those scripts. I, generally, use OS unattend XML to enable auto admin logon. But, when that is not done, there are situations when I have to enable this for a set of servers for doing application deployment that requires multiple reboots. So, the following function lets me enable auto-admin logon on a set of servers. This script requires remote registry service be enabled on the remote systems. If not, you receive an error. Also, the DefaultDomainName & DefaultUserName are not mandatory parameters. These are, by default, taken from the environment variables. AutoLogonCount can be used to disable auto admin logon after a specified auto logons. Again, this parameter is not mandatory. Here is the script:

I am also performing a few checks to make sure the architecture of PowerShell host you use is a valid one for the architecture of remote system. For example, if the remote system is x64 and you use a …

Test-WSManCredSSP: Check if a remote computer has WSMan CredSSP enabled

Update: This script won’t work against Windows 2003 or Windows XP systems. There is no CredSSP support on this and hence the WSMan:\<ComputerName>\Client\Auth\CredSSP or WSMan:\<computerName>\Service\Auth\CredSSP won’t resolve. You can use -ErrorAction SilentlyContinue along with Get-Item cmdlet when reading these values, if you don’t want to see an error. Thanks to @dfinke for reporting this. I’ve published a free book on PowerShell 2.0 remoting. You can download it at: When using PowerShell remoting, WSMan CredSSP is a requirement if there are multiple hops involved in the remoting scenario. When using remoting in an automation scenario, it becomes very important to know if the remote computer has CredSSP enabled or not. PowerShell v2 provides a cmdlet — Get-WSManCredSSP that tells you if CredSSP client or server  roles are enabled on the local computer. Make a note, I said “local computer”. This cmdlet, unfortunately, does not have a -ComputerName parameter. You may get a question, why not use Invoke-Command and run this cmdlet on the remote machine? Yes, we can do that. But, only if the remote computer …