Posts
49
Comments
83
Trackbacks
0
PowerShell
Running scripts that only work under 32bit cleanly in 64bit PowerShell

The scenario is as following: you have some script that can only work in 32bit powershell (the COM objects it calles only work in 32 bit for example) but you are used to running 64bit powershell. So what to do you do? Easy, just write your script to check if its being called from a 32bit process and if not, spawn a copy of 32bit powershell to run itself! Tha way you never have to think about calling 32bit powershell explicitly. Here is the snippet: ...

posted @ Wednesday, December 03, 2008 12:08 AM | Feedback (1)
Emacs powershell-mode.el updated to v0.5

Here is the updated file. The old v0.4 version can still be downloaded as well. Many thanks to Richard Bielawski for taking the time to update some things and fix bugs. Change list from Richard's diff: Indenting fixed on <tab> Elseif keyword added Support standard comment func Bug fixed when visiting files in major mode I didn't do a thorough test, simply used it in the following scenarios: visiting file, auto-load, colorization, indenting via <tab> and editing. Apologies for the dastardly delay--but if you have improvements and suggestions / snippets, I'd be happy to...

posted @ Tuesday, August 19, 2008 7:52 PM | Feedback (8)
PowerShell Book Recommendations

Someone asked me to recommend a few books, so here they are: 1) Windows PowerShell Cookbook by Lee Holmes (from PS Team) 2) Windows PowerShell in Action by Bruce Payette (from PS Team) 3) For Exchange specific stuff, I actually haven't tried any (makes sense as we were writing code most of the time :). Here are a few I dug up on the web, they look promising: In fact, a few guys I know wrote a very nice book that should definitely...

posted @ Sunday, February 10, 2008 5:30 PM | Feedback (1)
Announcing the Exchange 2007 PowerShell Scriptacular demo pack!

  Dear Exchange 2007 Enthusiast(s), I'd like to announce the Exchange 2007 PowerShell Scriptacular (download zipfile) demo pack. What is it you ask? Well... this collection of Exchange PowerShell scripts was developed by Mihai Jalobeanu and Vivek Sharma while they (we) developed the Exchange Management Shell. We had a lot of fun writing these scripts, and we used them to showcase the innovations in Exchange 2007 System Management--we also promised that when Exchange 2007 is released to the wild, that we'd make our favorite scripts available to everyone. So here they are! If you want our exact demo setup: to get...

posted @ Thursday, December 21, 2006 6:12 PM | Feedback (13)
How to get DL membership in Exchange 2007

Abshishek reminded me of this with his post on how to figure out Security Group membership using PowerShell. But Distribution Groups are a whole different beast. So how do you do it? One way is to use the GUI: the awesome Exchange Management Console already shows you group membership. And on the cmdline you can do this in Exchange 2007: Using server side filtering (faster):    $filterid = (get-user Administrator).Identity get-group -filter { Members -eq $filterid } Using client side filtering (slower):    get-group | where { $_.Members -like '*Admin*' } This can be adapted to do nested membership as well---I'll leave it...

posted @ Sunday, October 22, 2006 11:10 PM | Feedback (3)
How to record your shell session

PS> Start-Transcript PS> # do a bunch of stuff PS> Stop-Transcript # or just quit the shell This will create a file (by default in your My Documents folder) that is a verbatim copy of your shell session. No more copy and paste needed from the shell to notepad! A few other things of note: This is the only way to capture verbose and warning information as those cannot be redirected from the shell like errors can (don't ask me why, but make sure to tell Jeffrey Snover about this) You can start a transcript by default...

posted @ Sunday, October 22, 2006 11:10 AM | Feedback (0)
Looking for feedback on PowerShell and Exchange

Every once in a while its important to take a step back and see where we can improve---I already have a list of around ~150 things I'd like to improve in the Shell (Exchange and PowerShell), but I'd like to hear what you a) like about the shell and b) would like to see improved. You can leave comments, trackbacks on your own blogs, or mail me directly at (munging the address to defeat the spammers): vivek (at) thiswebpage'sdomainname.com   Here are some examples I found recently: Devin comments on how easy it is to move databases through cmdline and wonders why it isn't...

posted @ Friday, October 20, 2006 10:10 AM | Feedback (0)
A strict shell is sometimes a good shell

Sorry for yet another hiatus, times have been busy. To make up for it, here is one of my favorite improvements in PowerShell (BTW: this change was driven partly by REAL IT administrators at Microsoft---thanks folks, you rock!). So here goes. Do you know that in a normal session of PowerShell, unassigned variables are really "null" by default? This is an advantage for folks who love PERL and other Unix-y tools as they can use this assumption to their advantage. But, it also has potential pitfalls---let's say you make one minor mistake in a script and type $myvariabel instead of...

posted @ Saturday, October 14, 2006 8:10 PM | Feedback (0)
Sorting top users and then moving them (2003/2007)

Brian asked in the comments: "... I am looking for a monad scipt/command that will allow me to sort user on e2k3 by size then move either the top or bottom X number of users..." Try this on Exchange 2007, for 2003, you can use get-wmiobject cmdlet to read Exchange 2003 information using WMI. This is how you would get the top X users per server (you can optionally do this per database by passing in -database to get-mailboxstatistics): get-mailboxstatistics -server Myserver | sort TotalItemSize -desc | select -first 10 Then you can move this list directly using move-mailbox: get-mailboxstatistics -server Myserver | sort TotalItemSize -desc |...

posted @ Tuesday, September 19, 2006 5:09 AM | Feedback (1)
Community Run Scripting Contest

Thanks to Josh for organizing this. In addition to the offical Microsoft One-Liner contest for Exchange 2007, Josh has started his own scripting contest for PowerShell and Exchange. The best part about it is, that the winner gets a signed copy of the upcoming PowerShell book from Bruce Payette, one of the leading designers of PowerShell! Wow, nice job Jeffrey and Josh. So go forth and submit some scripts to both the official contest and Josh's. To sweeten the deal, if you end up winning either contest, I'll put your name, company, winning entry etc. on the official team blog (2 million readers per...

posted @ Saturday, September 16, 2006 2:09 PM | Feedback (2)
Blog hiatus or how to really enjoy your summer…

Well it had to happen. Now that Exchange 2007 Beta has shipped, its time for some rest and relaxation... as a direct result of that, this blog won't get updated for at least a month. Yikes! Where will people get their insider tips from?!? No worries though, I've been updating http://exchangeninjas.com with all kinds of good stuff (specially the FAQs). I'm hoping the community really gets active--just recently there was a massive article posted on understanding one of the cooles features in E2007: Autodiscover (thanks Ashish!). Of course, I can't leave on vacation for that long without leaving some tidbits of info...

posted @ Sunday, August 20, 2006 7:08 PM | Feedback (0)
Updated: PowerShell script editing mode for Emacs (powershell-mode.el)

I finally got around to updating my Monad... er.. PowerShell mode for Emacs. It has some minor changes, no functionality differences: Updated all instances of vmsh --> poweshell now that the name change is official File name changed from vmsh-mode.el --> powershell-mode.el In your .emacs, please change from (require 'vmsh-mode) to (require 'powershell-mode) Put the file in your site-list directory. \emacs\site-list or $home\site-lisp That's it! Here is the file. BTW: the file you'll download is powershell-mode.el.txt. You neeed to remove the ".txt" extension before you...

posted @ Saturday, August 05, 2006 7:08 PM | Feedback (7)
I’m a neeeenjjjaaaa now too!!!

exchangeninjas.com I registered and wrote my first tip and wiki edit. Totally cool! Looking forward to seeing more tips and tricks from the community.

posted @ Thursday, August 03, 2006 8:08 PM | Feedback (0)
Script to keep all your darned IE RSS subscriptions in sync on all your PCs

The new IE7 is pretty awesome. But to this day I'm amazed at why people continue to think of features in relation to just one computer or a disconnected computer. Its like the phone that isn't connected to the phone network. IE7's RSS features are comprehensive, but if you have more than one machine (laptop, home pc, work pc and so on), you'll quickly find yourself with new subscriptions on each different computer... So here's a little PowerShell one-liner to keep your subscriptions in sync (only works with IE7 installed). First export the current subscription on your first PC: $feeds = new-object -com...

posted @ Friday, July 28, 2006 10:07 PM | Feedback (0)
Sample Code: Calling Exchange cmdlets from .Net code

Now that CDOEXM and WMI providers are gone from Exchange 2007, many custom application developers are probably wondering: "what do I use instead?". The answer is the same as it is for admins who want to move from using CDOEXM/WMI to PowerShell, which is: use the Exchange cmdlets from code. The PowerShell SDK provides a great set of APIs that will let you host an instance of the PowerShell engine and run cmds / scripts through it. So let's talk about how to code against PowerShell. Think of the PowerShell engine as being similar to the SQL engine. Both engines do...

posted @ Thursday, July 27, 2006 8:07 AM | Feedback (20)
Videos: History behind Exchange Management Shell and some cool demos!

Mihai (awesome lead developer for the Exchange Management Shell) and I did a video series on some of our design decisions as well as the history behind why Exchange partnered with PowerShell/Monad in the first place. The second video has some neat demos that we did---just a little teaser for all of you who want to get Beta 2 (hint, keep watchin msexchangeteam.com for exact details on where to get it). Here are the videos:  Video: Vivek Sharma and Mihai Jalobeanu on Exchange Management Shell  Video: Exchange Management Shell in action  If you have any questions or feedback, please let us know.

posted @ Friday, July 21, 2006 4:07 PM | Feedback (0)
Register for Exchange 2007 Beta

Its almost time. In fact its so close to the beta that you might as well register for it now.Remember, this is how you get to play part in the PowerShell/Exchange scripting contest, try out all the cool new Exchange features (some that will be total suprises... in a good way) and start planning your upgrades. So go register now. Do it. Do it. Do it. Do it. Do it. Ok that was annoying. Do it. :-)  

posted @ Tuesday, July 18, 2006 10:07 PM | Feedback (1)
PowerShell snippet to get perfcounters

Somebody at work asked me whether its possible to get perfcounters through PowerShell. The answer, as with any question directed at this blog, is yes. Here is a little snippet below to do just that. Hint: its possible to compress this to a single line, experiment with passing in arguments to new-object it if you don't want to create a script like the one below:    param( $CounterName=$(read-host CounterName), $CategoryName=$(read-host CategoryName), $InstanceName=$(read-host InstanceName), $MachineName="." )  ## Example CounterName = "% Processor Time" ##         CategoryName = "Processor" ##         "_Total" ## ##   get-perfcounter "Disk Transfers/sec" "PhysicalDisk" "_Total"  $counter = new-object System.Diagnostics.PerformanceCounter $counter.CounterName = $CounterName $counter.CategoryName = $CategoryName $counter.InstanceName = $InstanceName $counter.MachineName = $machinename $counter

posted @ Monday, July 17, 2006 3:07 PM | Feedback (2)
Examples and more examples and Win A FREE trip to New York.

Guess what? I told a bunch of attendees at TechEd this so I will share it with the rest of you too. We will send one lucky person to NYC to attend the joint Exchange/Office/Vista launch event. Cool huh? All you have to do is submit a cool, useful one-liner for Exchange 2007 management. And you've got plenty of time too as the contest runs till September (read the rules). So to help you out we also up some great examples of how to use PowerShell with Exchange on the web. Check them out and remember to send us feedback: Exchange 2007 "Scripts"...

posted @ Saturday, June 17, 2006 2:06 PM | Feedback (4)
How to 2007: Setting the Journal Recipient in Exchange 2007

Whenever I do a webcast or presentation, I try to use examples which are immediately useable. Sometimes its tough to get a pulse on what are the frequent things that people do with Exchange, so I've been looking at what the community has written scripts for in 2003 and converting them to the equivalent in 2007. I hope that a) this will provide a "bootstrap" so you have some snippets to use immediately and b) that this will show you that cmdline/scripting in 2007 is much easier (you don't have to be afraid to learn about it or use it). Here's...

posted @ Saturday, May 20, 2006 5:05 AM | Feedback (0)
Tweak master flash (or how you can tweak community scripts too)

Joey asked a cool question on my last post on out-html: what if you wanted to colorize the output of out-html so that some rows/values were colored differently based on a criteria? I can think of a couple of different ways to handle this, and it certainly is a nice hack. But rather than building the solution, I'll post some hints and see if the community can pull some nice stuff together :). Here are some ideas: Since the goal is to color values in any given column/row a given color based on a certain criteria, why not parameterize this...

posted @ Thursday, May 11, 2006 10:05 PM | Feedback (2)
Technet Webcast follow-up (out-html, out-ie)

Thanks to all the cool folks who attended today's webcast: Exchange Server 2007 Management Shell and Scripting (Level 300). As promised, here are the scripts I used. I first saw Out-IE used by the awesome Jim Truher. I wrote it recently when one of my colleagues asked if we there was a way to pop-up html pages without calling IE manually. Here it is: $ie = new-object -com InternetExplorer.Application $ie.navigate("about:blank") while ($ie.busy) { sleep 1 } $ie.visible = $true $ie.document.write("$input") # if above line doesn't work on your system, uncomment line below # $ie.document.IHTMLDocument2_write("$input") $ie Put the lines above in a msh/ps1 file and...

posted @ Tuesday, May 09, 2006 8:05 PM | Feedback (10)
Get-Mailbox, the most popular cmdlet

I just noticed that I use Get-Mailbox everywhere in my examples. Why is that? I suppose its because this a) Exchange is all about Mailboxes (if you didn't know, Exchange is an e-mail / collaboration server) and b) its so easy to use. The basic pattern for Get-Mailbox is below:   Get-Mailbox If you just run this, the cmdlet will return upto 1000 mailbox enabled users. Why 1000? Well we have to cap our results somewhere, as if we returned everything, very large amounts of data would be returned. Small companies will never notice. Large companies can do: Get-Mailbox -resultsize 99999...

posted @ Thursday, May 04, 2006 10:05 PM | Feedback (4)
Drumroll please… Monad is now PowerShell

It was an amazing honor for me to be able to represent both the Exchange 2007 and PowerShell 1.0 products today at MMS. Jeffrey has a great write up (thanks for the plug Jeffrey!) and so does Lee. Download, enjoy the new features and keep the great community going strong :) BTW: In no particular order, my new favorite features in the latest PowerShell RC0 drop: User customizable tab completion. Wow. Out of the box it works with parameters and variables. That means you can do: get-command - and it will complete the rest! I've customized my shell to complete directory names when...

posted @ Tuesday, April 25, 2006 10:04 AM | Feedback (1)
Roundup: More “first reactions”, tutorials and some press

Well, until I can write more myself, I figured I'd share all the good content that is already being created by the community. Press: Windows IT Pro: Exchange 12 Shows Promise - "As noted previously, the new Exchange System Manager (ESM) GUI is completely redesigned and far less complicated than the current version... This is powerful stuff." Infoworld: A First Look at Exchange 12 - "The new version’s scripting capability is going to be a favorite new feature among overworked IT managers." InformIt: As Exchange 12 Looms, Microsoft Fixes Monad Bugs - The main issue in the article seems to be the upgrade from...

posted @ Sunday, April 09, 2006 4:04 PM | Feedback (0)
Roundup: “Intro to Exchange Management Shell” and “Using Monad to get unread mail”

Henrik Walther, one of our MVPs, put up an awesome introduction to Monad in Exchange 12 at msexchange.org. He covers the basics: starting the shell, running some simple "get" commands as well as move-mailbox. The article even has action shots! Nice work. Speaking of nice work, Glen continues his excellent series on how to use Monad to do existing tasks that are Exchange related. The point to be made here is that you don't need to wait for the release of Exchange 12 to start learning about and using Monad. The technology adapts well to exisiting systems by leveraging COM...

posted @ Saturday, March 11, 2006 11:03 PM | Feedback (0)
vmsh-model.el: v0.2 Emacs major mode for MSH (Monad) scripts

Here is a simple mode for editing MSH (monad) script files in Emacs. The syntax is easy to edit so if you need to add keywords or change highligthing, go for it! There isn't any indentation support yet, so you'll have to use the good old tab key for now. To use it, put the file (remove the .txt extension first) in emacs\site-lisp or your local lisp directory. Place the following in your .emacs to activate it: (require 'vmsh-mode) Enjoy! [update 1/17/06: Updated the file to version v0.2. The new version improves the syntax table] [update 1/21/06: Lee points out that...

posted @ Friday, December 23, 2005 3:12 PM | Feedback (0)
Exchange 12 Beta 1 is out

Betanews says: [snip]…A lot of work on Exchange 12 has been focused on administrative tools. The new release has been componentized and administrators can choose to install only the pieces they need. Exchange will also be able to automatically detect and configure end-user systems.Microsoft’s new command line shell, known as Monad, will make its first appearance in Exchange 12. The scriptable shell can be used for automating tasks, essentially providing command line control of Exchange that goes beyond the standard Exchange System Manager…[snip] Zdnet says: [snip]…The company is also adding a scripting tool that enables power users to write code...

posted @ Wednesday, December 14, 2005 12:12 PM | Feedback (0)
Serving up pages, MSH style

Well, blame this one on extreme boredom. I wish I could post all my Exchange 12 scripts… but now is apparently not the time. So I’ll post some of my Monad only tricks for now. If you think this is crazy / cool / useful / interesting… wait till we show you what you can do in Exchange using Monad. Stay tuned. The caveat on this script is: make sure to run this in a seperate MSH instance. Once you’re done serving up pages, close that instance. That way there isn’t a process thread lying around locking port 80. If...

posted @ Thursday, December 08, 2005 12:12 PM | Feedback (0)
Vmake.msh and format-source.msh: Making it easier to write snippets in C# using Monad

When I want to write a snippet (let’s say with 3-4 source files and maybe a lib reference), I don’t really want to go and create a project in Visual Studio… not because its not easy, but because opening up VS for some reason feels like I’m embarking on a serious project. And that’s not bad… after all, Visual Studio is really an enterprise and professional interface. For the minor snippets, its really easy to call csc directly and compile some files. But you then miss out on some features of an IDE… So I rolled some scripts to help...

posted @ Wednesday, October 05, 2005 12:10 PM | Feedback (0)
More on Exchange PDC 2005 demo

To make a long story short: I gave Adam our demo VPC of E12, which includes Monad, but then gave him the wrong password to unlock the machine… Dang it! Check the orginal article at proudlyserving.com. Only one more thing to add. So what exactly did we demo? Here it is. We used Use monad cmdlets, written by Exchange team to: Install and uninstall a demo managed Transport Agent Get the list of all running agents, their status and their priority Create a set of users in the...

posted @ Saturday, September 24, 2005 12:09 PM | Feedback (0)
PDC 2005: Summary

This PDC we made some bug announcements as a company (Sparkle, Longhorn, VS etc.), as well as some related to Exchange and Monad: We have deprecated and cut some APIs, full list is available through this blog entry at the Exchange blog. Bob Muglia (VP of Windows Server) put Monad on the roadmap as appearing in 2006 Exchange announced that Monad will be the way that users manage Exchange through script and cmdline Exchange announced that Exchange cmdlets will replace our WMI providers and CDOExM...

posted @ Thursday, September 15, 2005 12:09 PM | Feedback (0)
MSH Script: Get-URI

This was one of the first scripts I wrote in MSH (see Monad). Lee and Adam actually work on Monad so they take time to explain things, I'm just going to paste it with a brief summary since its not doing anything fancy. Update: Lee improved the script to use new features available in latest builds. Be sure to check it out! ## ## Vivek Sharma (viveksharma.com) - 1/4/05 ## Simple script to get a web page… Can’t really handle https ## or complex cookies. ## if ($args.Length -eq 0) {  write-object “`nYou did not pass in a URI`n”; return }  $webclient...

posted @ Saturday, August 06, 2005 11:08 PM | Feedback (0)
News
A little slow these days as I'm busy working on exchangelabs.com. I will try and post tidbits when I get some time. Enjoy the older posts till then!