PowerShell Team
Automating the world one-liner at a time…
Latest posts
Extending and/or Modifing Commands with Proxies
There are so many powerful features in V2, it is hard to know where to begin. This one is going to blow to top of your head off when you understand what it enables you to do. In this blog, I talk about Proxy Cmdlets which is the ability for one Cmdlet to call another. You could always do this but to do it right has always been very difficult. In particular, what you want to have happen is to be able to control the execution of the calling command - to control when it's BEGINPROCESS(), PROCESSRECORD(), ENDPROCESS(), etc methods are called so that it behave with the correct behavior. What yo...
Programming PowerShell_ISE
I recently wrote a blog Powershell_Ise Can Do a Lot More Than You Think where I described the ability to program it to do new stuff. Karl Prosser has picked up the baton and written some cool scripts programming the PowerShell_ISE to make it do some of the features that he had put into his amazing PowerShell Analyzer. I encourage you to read his blog and study his code so you get a feel for the sort of things you can do and then use Karl as your inspiration and write some of your own extensions and share them with the community. You can read Karl’s blog and get his code HERE. Cheers! Jeffrey Snover...
Diagnosing Here-Strings With PowerShell_ISE
James Brundage posted a blog entry How To Write a Console Application in PowerShell with Add-Type which used a here-string. One user (lcr) copied and pasted the text and got the following error: Unrecognized token in source text. At line:1 char:72 + Add-Type -OutputType ConsoleApplication -OutputAssembly HelloWorld.exe < <<< @" + CategoryInfo : ParserError: (:) [], ParentContainsErrorReco rdException + FullyQualifiedErrorId : UnrecognizedToken &...
How To Write a Console Application in PowerShell with Add-Type
Windows PowerShell CTP3 has a lot of very cool things. CTP2 introduced the Add-Type cmdlet, which allowed you to dynamically compile C# in PowerShell. It was actually possible to use the CompilerParameters to Add-Type to make a console application, but it wasn't particularly easy. In CTP3, we've made this a lot easier to do. There's now an -OutputType parameter for Add-Type. It can either output a Library (the default), a ConsoleApplication, or a WindowsApplication. Check out this really quick "Hello World" program built using Add-Type. Add-Type -OutputType Cons...
Get-Verb
.cmdletname { font-size:large } .cmdletsynopsis { font-size:medium } .cmdletdescription { font-size:medium } .cmdletparameters { font-size:medium } th { font-size: medium; font-style: italic } table { border: 1 } When I write a PowerShell function, I try to ensure that it follows the PowerShell standard verbs. These verbs actually exist as static properties in a few different types in PowerShell, so I thought I'd make a quick advanced function so I can get all of the Verbs. Check it out: Get-Verb Synopsis: Gets the standard PowerShell verbs ...
How and Why to Use Splatting (passing [switch] parameters)
On our internal discussion list, someone just asked about how to pass switch parameters from one function to another. This person asked this as "Why can't [switch] parameters be passed as parameters?". My short answer was simple: "They Can Be" Answering this question is a great way to illustrate the value of a PowerShell V2 feature called Splatting. Splatting is two things, it's a way to get all of the parameters passed to a function automatically (they're in a variable, $psBoundParameters), and it's a way to take a list or dictionary of arguments and pass them on to the next fun...
A Module to Create Modules and Advanced Functions
[1/3/09 Update - the original link to the attachment containing this code was broken but is now fixed. Sorry. jps] It is hard to overstate how important Modules and Advanced Functions are. If you are a PowerShell user - you need to take the time to learn these new mechanisms and use them as your first choice in implementing new functions. The reason for this is that these mechanisms are critical technologies to support SHARING. Advanced Functions provide help, parameter tab-completion, and cmdlet semantics that make it easy for other people to use your functions. Who...
PowerShell_ISE Scripting: ConvertTo-Comment
Let me combine a couple of things. 1) When I posted my PowerShell_ISE profile, I included a function Goto-Line that is now builtin to the ISE so I reposted the blog with this function commented out. I commented it out instead of deleting it because I wanted to provide an example of how to do it. 2) Vivek Sharma left a comment asked about programmatically controlling indentation so I gave a couple of pointers to the objects required to program the editor. So let’s take those 2 and put them together and write a function which will convert the selected text into a PowerShell comment (using another CTP3 fea...
I’m Changing My Name To Sznarwakowski
I was just reading a blog post where they were showing al the SCVVM commands in a list. I was going to refer them to my blog which shows how the display that list of commands in a really nice format. I have no idea where that blog post is so I decided to search for my name and scvvm. Here is what I got: I think I'm going back to the old family name: Sznarwakowski. Sure I'll spend the rest of my life telling people how to pronounce and spell it but at least I won't be confused with a serial killer/sex cannibal or an Enron felon. Oh wait! It gets better (worse?). I didn't rem...