Month: June 2010

Quick PowerShell Tip: Generating random filenames

While answering a question on Windows PowerShell forum, I came across a few interesting methods in the System.IO.Path namespace. One such method is GetRandomFileName(). This method can be used to generate a random, and cryptographically strong string that you can use as a folder or a file name. The usage is quite simple.

Also, there is another method GetTempFileName(). This method also generates a random (kinda.!) file name but always with a .TMP extension. Not just that, it also a creates a zero byte file on the disk and returns full path to the file.

There are many uses to these two methods. More on that later.!

PasteBin.com WPF addon for PowerShell ISE

In my last post, I showed you a teaser of an upcoming post. So, this post is about the PowerShell ISE and PowerGUI 2.1 Script Editor (PGSE) addon for uploading code to PasteBin.com. This happens to be my first WPF addon for PowerShell ISE. The PGSE version of this will soon be out. I am looking at working around a bug in PowerShell. Looks pretty hard right now.   Now, coming to the subject, this addon module is written in such as way that it detects what scripting environment you are using and then extends the script editor menu options to add “Send to PasteBin” item. When you select some text in the editor and click “Send to PasteBin” or CTRL+B, the following WPF window appears.    You will see the above interface in PowerShell ISE. The top text box will have the content you selected in the script editor. The remaining options are quite self-explanatory. You can read about these options at http://pastebin.com/api.php.   You can use the “save preferences” button to make this addon remember you email ID, …

Send content to PasteBin using PowerShell

PasteBin.com is a good way to share scripts with others. Over there, you can just paste scripts written in almost any language and select the language for syntax highlighting. The interesting part here is that they provide an API to do that. Like anything else that got an API, this one can also be scripted using PowerShell. So, here is a simple module that lets you paste content to PasteBin using PowerShell.         

The usage of this is quite easy. There is really only one mandatory paramter, pasteCode. This parameter is used to specify the script code that you need to upload to PasteBin. Other parameters can be quite helpful. For example,    You can use pasteFormat to specify the language of the script so that PasteBin can enable syntax highlighting  pasteSubDomain to specify a subdomain name to upload your scripts to. For example, http://ravikanth.pastebin.com has all the script uploaded by me pasteEmail to send you an email with the PasteBin link pasteExpireDate to set how long the pose will be kept online and pastePrivate switch parameter to hide …

.NET isolated Storage in PowerShell: user store vs machine store

This post has been in draft for a long time. So, clicking publish today 🙂  In a couple of earlier posts, I wrote about using .NET isolated storage and an example showing a use case for this. In today’s post, I will explain the differences between user store and machine store. I admit, this has nothing to do with PowerShell. This is more of a .NET related post but as always, I will use PowerShell to explain this.  When you look at the .NET namespace to create/manage isolated storage in PowerShell, you will find that there are different methods to create isolated storage. These methods include  GetUserStoreForAssembly() GetUserStoreForApplication() GetUserStoreForDomain() GetMachineStoreForAssembly() GetMachineStoreForApplication() GetMachineStoreForDomain()  So, there are two types of stores and different ways to create/manage these stores. For the sake of today’s discussion, I will talk about GetUserStoreForAssembly() & GetMachineStoreForAssembly()  So, when you use GetUserStoreForAssembly(), isolated storage will be created under the AppData folder within the the user’s profile folder. For example, C:\users\User1\AppData\Local\isolatedStorage. In case of a machine store, you will find an isolatedStorage folder under C:\users\AllUsers profile.  How …

Install and configure iFilters for SharePoint 2010 using PowerShell & updated PS SP2010 Utils

This is one of the recent additions to my SharePoint 2010 PowerShell scripts & Utilities project on Codeplex. I wrote a generic script cmdlet to take care of iFilter MSI install, make changes to DOCICON.XML, and add the crawl extension to the search service application. This could be useful to those who perform frequent SharePoint 2010 farm configuration. You can copy just this script @ http://pssp2010utils.codeplex.com/SourceControl/changeset/view/14b6c2e1b6ec#SPInstallUtils.psm1 This script requires to be run at the SharePoint 2010 management shell since there is a dependency on New-SPEnterpriseSearchCrawlExtension cmdlet. Whatever iFilters I’d Installed so far were all MSI with silent install support. So, making this a generic script cmdlet was a choice for me.

You can find the complete documentation of PSSP2010Utils @ http://pssp2010utils.codeplex.com/documentation