background preloader

Blogs

Facebook Twitter

PowerShell Out-GridView–A cmdlet with benefits. A question I often get about PowerShell from ex-UNIX developers is whether or not PowerShell can “tail” files.

PowerShell Out-GridView–A cmdlet with benefits

Unfortunately, there is no direct analogy to the tail command in PowerShell. It’s typically used to watch the contents of a log file live as it is added to, and that is certainly something that PowerShell can do. This question comes from a developer who is using NLog to log messages from his app involving Reactive Framework code. Get-Content –Wait C:\Test.txt Get-Content is a PowerShell cmdlet (aliased to type (for DOS people) and cat (for Unix people)). It reads the content one line at a time and returns a collection of objects, each of which represents a line of content. The –Wait parameter waits for content to be appended to the file. Out-GridView You can pipe the results of PowerShell to a grid view window where the output is displayed in an interactive table.

Features of Out-GridView Hide, Show, and Reorder ColumnsSortQuick FilterCriteria FilterCopy and paste How To. Managing Active Directory with Windows PowerShell. PowerShell Tutorial 12 – Part 1: Active Directory Management Microsoft Active Directory Implementations have grown so large and complex that it’s required to have the necessary skills to play at the next level.

Managing Active Directory with Windows PowerShell

What is the next level for an Administrator who is chained to the ADUC GUI? One that comes to mind is the skill to implement web systems that empower users to modify their own Active Directory Account information. Another, which our team completed was an implementation that auto generates Active Directory Accounts through our HR system. Accounts are created, modified, and disabled based on their status within the HR system. Finding Related WMI Classes (and Drive Letters) - Dreaming in PowerShell. Recently, I was asked how to find the drive letter when all you knew was a partition or disk index.

Finding Related WMI Classes (and Drive Letters) - Dreaming in PowerShell

Hmmm. Accessing Related WMI Classes After some scratching the head, the solution was simple. WMI internally maintains relationships between related classes. There are two WMI classes of interest here. Unfortunately, WMI relationships are not directly exposed in PowerShell. Get-ScriptDirectory to the Rescue - Windows PowerShell Blog. The other day I was writing a script and decided that I wanted to break it into a couple of files and have the main script dot-source a library script in the same directory.

Get-ScriptDirectory to the Rescue - Windows PowerShell Blog

Here is the problem that I ran into: PS> Get-ChildItem Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\testMode LastWriteTime Length Name---- ------------- ------ ----d---- 6/19/2007 6:12 AM subdir-a--- 6/19/2007 6:12 AM 47 Invoke-Test.ps1-a--- 6/19/2007 6:12 AM 47 LibraryTest.ps1PS> Get-Content Invoke-Test.ps1. . \LibraryTest.ps1echo "I Love PowerShell"PS>PS> Get-Content LibraryTest.ps1function echo ($msg){ write-host $msg}PS>PS> C:\temp\test\Invoke-Test.ps1I Love PowerShellPS>PS> Set-Location subdirPS> C:\temp\test\Invoke-Test.ps1The term '. \LibraryTest.ps1' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.At C:\temp\test\Invoke-Test.ps1:1 char:2+ . <<<< . The problem is that when the script dot sources the library (". . So you do you figure this out?

Shay Levy. I’m a Microsoft MVP… Again June 30, 2013 It's that time of the year which feels like having a second birthday.

Shay Levy

I'm proud to announce that I was awarded the MVP title once again. Powershell - Make-PS1ExeWrapper. Occasionally folks want to be able to create an EXE from PoweShell.

Powershell - Make-PS1ExeWrapper

PowerShell can’t do this by itself but this can be done with PowerShell script. Essentially what you can do is create a simple console EXE program that embeds the script as a resource and the EXE, upon loading retrieves the script and throws it at a PowerShell runspace to execute. Here’s the script for a feasibility test of doing this very thing. Scriptblock Surprises. Prof.

Scriptblock Surprises

Powershell Scriptblock Surprises PowerShell Functions can save you time. Scriptblocks save you even more time. Switch Way Did They Go? Prof.

Switch Way Did They Go?

Powershell Switch Way Did They Go? Pair up Regex with the Switch construct to get what you need, in plain English. I know we've had some introductory lessons in the past on the Switch construct. This construct evaluates some expression against a collection of values. When this code is executed the value of $choice is compared. Regular expressions are an incredibly vast topic. Andy Schneider's Blog about Windows PowerShell. Jonathan Medd's Blog. PowerShell V2: ParameterSets - Windows PowerShell Blog. One of the great benefits of PowerShell V2 Advanced Functions is the ease in which you can support parametersets.

PowerShell V2: ParameterSets - Windows PowerShell Blog

ParameterSets are, well, different SETS of valid parameters. For instance you can say: Get-Process -id 0 Get-Process -Name *ss Those are 2 different parametersets for the Get-Process cmdlet. Here is an example of how you would code parametersets using advanced functions: function test-param { param( [Parameter(ParameterSetName="p1",Position=0)] [DateTime] $d, Use of Wildcards in PowerShell Formating - Windows PowerShell Blog. MMS in San Diego was a great conference!

Use of Wildcards in PowerShell Formating - Windows PowerShell Blog

I met lots of customers that asked lots of great questions. I was demonstrating PowerShell's WMI support when a customer asked about controlling the output. The problem was that PowerShell was showing all the WMI System properties as well as the Object properties and that this wasn't what they wanted. PowerShell makes WMI objects look like any other object so there is no "special" processing for WMI so the question is, can you do the equivalent of -EXCLUDE __* (All WMI System Properties start with "__").

Let me illustrate the problem: Fun with Script Cmdlets - Windows PowerShell Blog. Script Cmdlets are one of the coolest things about the newer version of PowerShell. A Script cmdlet allows you to use all of the variety of cmdlet parameter sets inside of PowerShell functions. Since Script Cmdlets are PowerShell functions, and the PowerShell engine prefers to run functions rather than commands, you can use Script Cmdlets to override an existing cmdlet. You might want to do this to add or remove parameters from a cmdlet you use often. Also, you might just want to see what a cmdlet’s parameters look like in a script cmdlet, so you can go write your own. Frank's At It Again: Another Free PowerShell Book - Windows PowerShell Blog.

Frank Koch is an Infrastructure Architect in the Technet team in Switzerland. In THIS blog entry, I talked about how Frank wrote a very popular Windows PowerShell book and made it available FREE (aahhhh - there is that magical word again! :-)). Needless to say, he had a lot of downloads. Motivated by that success, and his love of PowerShell, Frank is at again with a new FREE PowerShell Book.

This time the focus of the book is on Server Administration. Working With Web Services (Post CTP2 V2 Feature) - Windows PowerShell Blog. Let me start by first apologizing for sharing some information that you are not going to be able to go out and try right away. During one of the interactive Q&A sessions at TechEd, people asked about working with Web Services.

I referred to a feature that we were working on and then Hal Rottenberg asked me to blog about some of the details. I'm not sure that this is a good idea because while we have it coded up and in the nightly builds, that is not a guarantee that it will make it into the next version (we often have to cut features in order to create bandwidth to increase the quality of other features). That said, I'm going to go out on the limb a bit and share with you what we are working on. First let's start with motivation (you should always start with motivation. As such, we have speced and implemented the cmdlet: New-WebServiceProxy. Custom Certificate Request in Windows Vista - Ask the Directory Services Team. James Carr here and I would like to discuss creating custom certificate request in Windows Vista. When requesting certificates from a Windows 2000/2003 Enterprise Certification Authority, we will use one of the built-in certificate templates.

Certificate Templates are used to tell the CA what information should be included in the issued certificate. For more information about certificate templates, please see the following: Certificate Templates. How to detect a 32 or 64 bit OS « Brady's Contentious Blog. “A jug fills drop by drop” – Quest PKI Cmdlets - Windows PowerShell Blog. The Buddha once said that, “A jug fills drop by drop”. In this case, the jug is universal PowerShell cmdlet coverage which is a really large jug! We’ve never been confused on this point – I’ve often referred to it as the “30 year hole” that we needed to dig ourselves out of. When PowerShell V1 shipped, it had a very small number of cmdlets.

It was mostly used by advanced scripters to script their own solutions. Soon afterwards, the Exchange team released 400+ cmdlets and then it was reasonable for Exchange admins to manage their Exchange tasks. That is a great bit of philosophy but the reality is that if you need cmdlet coverage and it isn’t there, you are sucking wind. PowerShell on-line help: A change you should make for V2 (#3) (and How to Author MAML help files for PowerShell) - James O'Neill's blog. In the last could of “change you should make” posts I’ve talked about a couple of things which turn Functions from being the poor-relation of compiled Cmdlets (as they were in PowerShell V1) to first class citizens, under V2.

Originally the term “Script Cmdlets” was used but now we call them “Advanced functions”. This is quite an important psychological difference because writing a cmdlet – even a “script cmdlet” sounds like difficult, real, programming. On the other hand an advanced function sounds like a function with some extra bits bolted on and nowhere near as daunting. In V2 there is a new version of the Tab-Expansion function which completes names of functions and fills in parameters , and that doesn’t need any change to the code. A Module to Create Modules and Advanced Functions - Windows PowerShell Blog. [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.

On PowerShell function design: vague can be good. - James O'Neill's blog. There is a problem which comes up in several places in PowerShell – that is helping the user by being vague about parameter types. Consider these examples from my Hyper-V library for PowerShell 1. Draft - Creating Cmdlet Help - Windows PowerShell Blog. PowerShell Modules: A change you should make for V2. (#2) - James O'Neill's blog. A few days back I wrote about PowerShell version 2’s ability to confirm whether it should be changing something. Since I was writing something which would some pretty drastic changes , supporting –WhatIf and –Confirm for almost no effort seems like a huge win. The next thing I wanted to cover was modules.

More PowerShell: A change you should make for V2. (#1) - James O'Neill's blog. How to Improve the Performance of a PowerShell Event Log Query - Hey, Scripting Guy! Blog. Ink - PowerShell20. Community for .NET developers everywhere. Multiparadigmatic C# Back in June of last year, at TechEd 2010, the guys at DeepFriedBytes were kind enough to offer me a podcasting stage from which to explain exactly what “multiparadigmatic” meant, why I’d felt the need to turn it into a full-day tutorial at TechEd, and more importantly, why .NET developers needed to know not only what it meant but how it influences software design. They published that show, and it’s now out there for all the world to have a listen. For those of you who didn’t catch the tutorial pre-con at TechEd, by the way, I’ve since had the opportunity to write about it as a series in MSDN magazine as part of my “Working Programmer” column. First piece is from the September 2010 issue, and continues through this year’s articles (I’ve got one or two more yet to write, so it’ll probably turn out to be about 12 pieces in total).

And yes, multiparadigmatic is a word, and yes, it is the longest word I’ve ever used in a talk title. Effective PowerShell Item 4: Commenting Out Lines in a Script File. OK the last couple of items have been long. I promise a short one here. Effective PowerShell Item 10: Understanding PowerShell Parsing Modes. The way PowerShell parses commands can be surprising especially to those that are used to shells with more simplistic parsing like CMD.EXE.

Effective PowerShell Item 9: Regular Expressions – One of the Power Tools in PowerShell. Windows PowerShell is based on the .NET Framework. That is, it is built using the .NET Framework and it exposes the .NET Framework to the user. One very nice feature of the .NET Framework is the Regex class in the System.Text.RegularExpressions namespace. It is a very capable regular expression engine. PowerShell V2 – External MAML Help - Windows PowerShell Blog. Effective PowerShell Item 1: The Four Cmdlets That are the Keys to Finding Your Way Around PowerShell. Effective PowerShell Item 2: Use the Objects Luke. Use the Objects! Effective PowerShell Item 5: Use Set-PSDebug -Strict In Your Scripts – Religiously. Poshoholic. PowerGUI Visual Studio is now in beta! « Poshoholic. Announcing the PowerShell Configurator. - James O'Neill's blog.

PowerShell.nu. Projects. Parsing XML Files with PowerShell. Cmdlet Help Editor V2.0 with Module Support - Windows PowerShell Blog. Blog.powershell.no. Resolve-ShortcutFile - Windows PowerShell Blog. Merry Christmas From PowerShell: The CodeDownloader Module - Windows PowerShell Blog. How objects are sent to and from remote sessions - Windows PowerShell Blog. Combining Powershell and Sysinternals–Closing a File Handle « Energized About Technology. Windows, PowerShell and WMI - Unveiling Microsoft's Best Kept Secret - Windows PowerShell Blog.

Testing cmdlets with FxCop - Windows PowerShell Blog. NetCmdlets Beta 2 is now Available. - Windows PowerShell Blog. How does Select-String work with Pipelines of objects? - Windows PowerShell Blog. Select-String and Grep - Windows PowerShell Blog. Active Directory Powershell Blog. Active Directory Administrative Center for Windows Server 2008 R2 implemented using ADPowershell! - Windows PowerShell Blog. Rename-Drive : Renaming Drives with PowerShell & WMI - Windows PowerShell Blog. Encoding Operations Knowledge - Windows PowerShell Blog. Emit-XML - Windows PowerShell Blog. Test-PSCmdlet - Windows PowerShell Blog. Using windows scheduler to run powershell scripts « Next – Next – Next – Finished. Does Your Hard Work Advance the Ecosystem? - Windows PowerShell Blog. Search - MSDN Blogs.