Keith Hill's Blog News Feed 
Monday, July 21, 2014  |  From Keith Hill's Blog

When PowerShell 4.0 shipped, the major new feature was DSC or Desired State Configuration – a very convenient and declarative way to manage the configuration of your Windows servers.  However as a developer whose IT department doesn’t really allow me … Continue reading

Monday, April 28, 2014  |  From Keith Hill's Blog

Your first instinct might be to check [IntPtr]::Size but that only works for the current PowerShell process.  In this scenario you want to check any arbitrary process running on the machine.  There doesn’t seem to be a .NET API for … Continue reading

Friday, October 25, 2013  |  From Keith Hill's Blog

You can get PowerShell 4.0 for down level operating systems now via the WMF 4.0 download.  NOTE: Be sure you have .NET 4.5 installed *before* you install WMF 4.0.  For various reasons, the WMF 4.0 installer doesn’t alert you to … Continue reading

Monday, October 21, 2013  |  From Keith Hill's Blog

This is a crude approach but works for capturing the main window of an application who’s process object you can find –typically via Get-Process.  If you run this script from PowerShell.exe or PowerShell_ISE.exe you will capture a screen shot of … Continue reading

Saturday, October 19, 2013  |  From Keith Hill's Blog

When Windows PowerShell 3.0 shipped, the team created an extensibility mechanism to allow a third party to “take over” the line editing experience.  That hook is a function called PSConsoleHostReadline that PowerShell will call – if it exists – to … Continue reading

Thursday, October 17, 2013  |  From Keith Hill's Blog

We released a minor update to PSCX that adds support for Windows PowerShell 4.0 in addition to its support for PowerShell 3.0.  You can grab the updated bits for your shiny new Windows 8.1 or WMF 4.0 install here.

Tuesday, October 1, 2013  |  From Keith Hill's Blog

Windows 8 introduced a new API for modern applications called the Windows Runtime or WinRT for short.  One of the hallmarks of this API is that it eschews synchronous methods for calls that could take longer than 50 milliseconds.  The … Continue reading

Friday, July 26, 2013  |  From Keith Hill's Blog

A few weeks ago I had the need to customize DCOM launch & activation permissions for a COM component.  I came up with this hack, er script, that I thought I would share “as-is”.  If anybody wants to take this … Continue reading

Saturday, July 20, 2013  |  From Keith Hill's Blog

The big new feature in Windows PowerShell 4.0 is Desired State Configuration however there are a number of other minor features one of which is a new common parameter called PipelineVariable.  This parameter allows you to store the current pipeline … Continue reading

Thursday, May 9, 2013  |  From Keith Hill's Blog

I have some older hardware running Windows 7 Media Center.  Normally we let the Media Center just go to sleep on its own but I’ve been concerned that it isn’t sleeping as much during there wee hours of the morning … Continue reading

Friday, April 5, 2013  |  From Keith Hill's Blog

If were following good security practices we run our Windows system with UAC enabled.  This means that if you forget to launch your PowerShell prompt as Administrator when you run a script that requires administrative privilege then that script will … Continue reading

Friday, January 11, 2013  |  From Keith Hill's Blog

You can download it here.

Sunday, September 16, 2012  |  From Keith Hill's Blog

Oisin and I have been busy prepping the PowerShell Community Extensions to support Windows PowerShell 3.0.  With this release, we are providing two packages.  There is a Pscx-2.1.0-RC.zip that is xcopy deployable just like PSCX 2.0.  Just remember to unblock … Continue reading

Friday, July 27, 2012  |  From Keith Hill's Blog

We’ve just released a beta of the PowerShell Community Extensions 3.0 which targets PowerShell 3.0 specifically.  This new version uses a WiX based installer.  We may look at providing an xcopy deployable ZIP file but we had so many users … Continue reading

Monday, April 30, 2012  |  From Keith Hill's Blog

PowerShell V3 now supports the ObsoleteAttribute for compiled cmdlets but unfortunately not advanced functions.  This is handy to let your users know that a binary cmdlet will be going away in a future release of your binary module. As we … Continue reading

Monday, March 5, 2012  |  From Keith Hill's Blog

One of the many new features in Windows PowerShell V3 is better support for alternate data streams (ADS) in NTFS files.  ADS allows an NTFS file to contain additional data that is not part of the “main” stream i.e. the … Continue reading

Monday, January 2, 2012  |  From Keith Hill's Blog

Within PowerShell it has always been easy to pass “simple” arguments to an EXE e.g.: C:\PS> ipconfig -all However passing arguments to certain exes can become surprising difficult when their command line parameter syntax is complex i.e. they require quotes … Continue reading

Monday, December 5, 2011  |  From Keith Hill's Blog

You can grab the bits from here. If you have V3 CTP1 installed, please uninstall it first or you can get your machine into a bad state. So far my favorite two features new to this drop are both in … Continue reading

Thursday, October 20, 2011  |  From Keith Hill's Blog

Windows PowerShell version 3 introduces a simplified syntax for the Where-Object and Foreach-Object cmdlets.  The simplified syntax shown below, eliminates the curly braces as well as the need for the special variable $_. C:\PS> Get-Process | Where PM -gt 100MB … Continue reading

Monday, September 19, 2011  |  From Keith Hill's Blog

I just uploaded beta 1 for the PowerShell Community Extensions version 2.1.  This beta drop adds better support for Windows PowerShell V3 that is in the Windows 8 Developer Preview.  There are a number of bug fixes in this drop: … Continue reading

 Keith Hill's Blog News Feed 

 Technorati Search for: PowerShell AND (Cmdlet OR Provider) News Feed 

One of the big benefits of Windows 2008 R2 is the fact that PowerShell v2 is installed by default and that AD can be administered by PowerShell. There are 76 AD cmdlets and an AD provider. We’ll start by looking at the cmdlets. Organizational Units are the subdivisions with a domain. We can easily create a new OU. New-ADOrganizationalUnit -Name "AllUsers" -ProtectedFromAccidentalDeletion $true The default location is to create OUs in the root of the domain. I really like the ability to...( read

From what I can see, CTP3's scoped execution policy settings can be used to cause a change in PowerShell behavior that can't be reversed intuitively. See this suggestion on Microsoft Connect: Possible need for Clear-ExecutionPolicy https://connect.microsoft.com/feedba...9788&SiteID=99 Basically, PowerShell sessions inherit machine-scoped execution policies until you define an execution policy with user scope. Once you've created a user-scoped execution policy, you can modify it, but

Updated to PowerBoots 0.1 An introduction to PowerBoots Please excuse me if I start by just copying the basic ideas of the Shoes Tutorial , but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start. PowerBoots (or just “Boots”) is a PowerShell 2.0 module with functions for writing Windows Presentation Framework ( WPF ) applications in the PowerShell scripting language. You should get the latest version of PowerBoots before continuing, and ins

Andrew Kutz just posted a new Hyper9 Cmdlet on sourceforce.net called Out-DataSet. Out-DataSet is an extremely useful and needed cmdlet. You can use it to pipe any type of data that can be formatted with the built-in cmdlet, Format-Table, into a typed Microsoft .NET System.Data.DataSet. This allows an unlimited manipulation of data that you simply cannot achieve with text globbing. This cmdlet is experimental in nature because it was achieved by reverse engineering the Format-Table cmdlet

• Updates : 3/28/2009 and 3/29/2009 Note: This post is updated daily or more frequently, depending on the availability of new articles. Entity Framework and Entity Data Model (EF/EDM) • Julie Lerman takes on many-to-many associations again in her Inserting Many to Many Relationships in EF with or without a Join Entity post of 3/29/2009. Binary Bob ’s Disconnected Clients, Changed data and Entity Framework post of 3/25/2009 discusses the use of EF with Silverlight apps. B

Ya hemos comentado en articulos anteriores sobre Windows Powershell lo que son los commandlets. Hoy vamos a ver uno de ellos que nos facilitara en un momento dado el trabajo. 4.1- Get-command Este cmdlet obtiene informacion basica acerca de los cmdlets y otros elementos de comandos de Windows Powershell como archivos, funciones y proveedores de Windows Powershell. Parametros: -name Obtiene...

While I finish up another blog solution, this time on importing a table from Word into Excel, I thought I would share some information on two useful tools you guys can leverage when building Open XML solutions. The first tool I want to talk about is the next release of PowerTools for Open XML. PowerTools for Open XML is an open source project on CodePlex , which is entirely based on version 1 of the Open XML SDK. This tool supports the PowerShell piping architecture, by providing 30+ cmdlets.

This is a bit of a hardcore example of the power that modules have brought to the table in v2.0. First, a little background - PowerShell’s type adaptation system has always ignored the concept of interfaces. Frankly, it never really needed to pay them any attention. The adapted view of any instance of a .NET class is just an aggregate of all its methods; the most derived instance is the default, and only, view. This is the most simple and most frequently used view. However, this all goes to hell

————————————————————————————————————— ————————————————————————————————————— Veeam Software , award-winning provider of systems management tools for VMware virtual datacenter environments, today delivers new executive management reporting, integration with corporate CMDBs (change management databases), new change management capabilities, and numerous technical enhancements in version 3.5 of its Veeam Reporter and Veeam Reporter Enterprise products. Veeam Reporter is a favorite of virtual

If you’re getting your Powershell on ( and frankly you should ), Microsoft have released a ~440 page compendium ( in *.docx format )   of Cmdlets you can use under the SCVMM Powershell. Now just remember the easiest way to get thru the document is view the Document Map . ( click View and then select the Document Map check box ) The reference is a prettied up and portable version of:  Get-Command -PSSnapin Microsoft.SystemCenter.VirtualMachineManager | Sort?Object Noun, Verb | Get-H

  Silverlight / WPF Boss Launch Beta (Andy Beaulieu) Silverlight RPG: Steel Saga (Avi Pilosof) Silverlight 3 Beta - Downloads You May Have Missed (Bart Czernicki) Compile your XNA 2D games to run in Silverlight with SilverSprite (Bill Reiss) Silverlight, XAML & Prism: Diving in Head First at the Shallow End of the Pool (Bobby Johnson) Creating Sound Using MediaStreamSource in Silverlight 3 Beta   and   Using Blur to make Dialogs Pop in Silverlight 3 (Pete Brown)

A Podcast about Windows PowerShell. Listen: In This Episode Tonight on the PowerScripting Podcast we talk to Brandon Shell about Active Directory support in PowerShell V2 News This segment is brought to you by Idera: Want to make Windows PowerShell easier than ever to learn and master? Checkout Idera’s PowerShellPlus Professional Edition which is now available for download! The new version has vastly improved code completion and a slick interactive Learning Cen

Windows Azure, Azure Data Services, SQL Data Services and related cloud computing topics now appear in this weekly series. Note: This post is updated daily or more frequently, depending on the availability of new articles. • • • Updated 3/20/2009 and 3/21/2009: Additions •• Updated 3/19/2009 10:00 AM PDT: Addition of more MIX 09-based content • Updated 3/18/2009 11:00 AM PDT: Additions: Windows Azure Tools and SDK March CTP update, ADO.NET Data Services 1.5 March CTP

There’s a bit of a flap going on now around the blogosphere as various vendors, eager to get onto the PowerShell train, are doing the bare minimum to get their product “powershellized.” No one has spent any time reading – or if they did, they weren’t successful in trying to understand it – the Microsoft Command Line Standard . Modules as Namespaces That’s right, modules are not as crazy sounding as they seem. They can be used quite simply to just group a load of function

GoGrid continues to be a pioneering force in Cloud Computing Infrastructure and Hosting segments with a variety of initiatives, making it a clear choice for Windows Server 2008, 2003, SQL Server and .NET developers. San Francisco, CA ( Vocus / PRWEB ) March 17, 2009 — GoGrid , the Cloud Computing division of ServePath , LLC delivers a solid implementation of programs, services and features optimized for Mi

After being a part of a few email threads and discussions about Citrix not following the traditional name-verb cmdlet naming scheme I thought I would make a post with my take on that. Basically, Citrix joined companies like Microsoft, VMware and Quest and is also trying to PowerShell-enable all of their products. However, they chose to not follow the standard naming scheme and went with a few of their own. The ones for Provisioning Server are just bad: They user verb instead of a noun, p

Windows PowerShell で SQL Server 2008 を管理する方法を調べてみました。 今回使用した SQL Server は SQL Server 2008 Express になります。 最初、SQL Server 2008 Express では Windows PowerShell が使用できないかと思っていたのですが、Windows PowerShell 1.0 を先にインストールしておけば、SQL Server 2008 Express でも Windows PowerShell で SQL Server を操作できるようになります。 SQL Server PowerShell is an option component in SQL Express 2008. Optional in this case means that we do not make Windows PowerShell 1.0 a prerequisite for SQL Express 2008, but it is required to use the new

Windows Azure, Azure Data Services, SQL Data Services and related cloud computing topics now appear in this weekly series. Note: This post is updated daily or more frequently, depending on the availability of new articles. ••• Updated 3/12-15/2009: More Additions (Amazon EC2 and Rackspace Cloud Servers price war, more S[S]DS updates) • • Updated 3/11/2009: Additions (mostly about the SDS course reversal) • Updated 3/10/2009 to add SQL Data Services Abandons REST

My job as an evangelist focuses on Windows platform (client and Server OS), including management (i.e. PowerShell) and Virtualization. But there are other Microsoft products which from my day to day use of them I feel evangelical about. One is Windows Live Writer which is the best tool for composing blog posts that I’ve found. Word can do blog posts, but somehow writer feels better suited to the task. I used to do a lot with office Communications server (and I’ve written sections for both of

Matt Uyttendaele , from Microsoft Research, contacted me about using PowerShell to transform files for the Microsoft ICE product. Microsoft Image Composite Editor is an advanced panoramic image stitcher which creates multi-resolution tiled formats like HD View and Silverlight Deep Zoom . We went from this To This Matt wanted to convert to Xml, laying out nodes for the file name, X and Y translation and in the process apply the scaling factor from the matrix to each coord

 Technorati Search for: PowerShell AND (Cmdlet OR Provider) News Feed 

 Mabsterama : powershell News Feed 
Tuesday, November 6, 2007  |  From Mabsterama : powershell

I'm writing this post from version 12.0.1366.1026 of Windows Live Writer - updated as part of Windows Live Wave 2 of the Windows Live suite of applications, which was released overnight. That includes a new version of Live Messenger, Live Mail, Live Photo Gallery etc.

Also released this week was the first alpha of Paint.NET 3.20. I don't know many people who still don't use Paint.NET, but it's an invaluable addition to Windows if you do any kind of image manipulation. See Rick's blog post for the full list of new features and changes in this version.

And lastly we have the first CTP of PowerShell 2.0! Remember that this is a CTP drop, so it's not for installation on production machines. See Jeffrey's post about CTPs if you're not sure.

Tuesday, January 9, 2007  |  From Mabsterama : powershell

In my last post I described a way to list out all your subscribed feeds that haven't been posted to in four months. This works well, but leaves it up to you to do something with those feeds.

The next logical step is to let PowerShell worry about them. That is, have the script itself automatically delete the feeds, or perhaps move them to a "Dead" folder for you to keep an eye on.

Now, the current version the PowerShell Community Extensions does not have a FeedStoreProvider that supports the "move-item" command, but that'll change soon (I've already written the code). In the meantime, here's how you'd delete the old feeds:

cd feed:\
gci -rec |
	?{ $_.Type -eq "Feed" } | 
	%{ $_.Items | sort -desc PubDate | select -first 1 } |
	?{ $_.PubDate -lt [DateTime]::Now.AddMonths(-4)
		-and $_.PubDate.Year -gt 1899} |
	%{ $_.Parent } |
	remove-item -recurse

Note the "-recurse" parameter on remove-item. That's because feeds are technically containers (they contain feed items), so unless you specify the "-recurse" parameter you will be prompted to delete each feed.

Next, here's how you'd move the old feeds to a "Dead" folder:

cd feed:\
new-item -itemType Folder Dead

gci -rec |
	?{ $_.Type -eq "Feed" } | 
	%{ $_.Items | sort -desc PubDate | select -first 1 } |
	?{ $_.PubDate -lt [DateTime]::Now.AddMonths(-4)
		-and $_.PubDate.Year -gt 1899} |
	%{ $_.Parent } |
	move-item -destination \Dead

One small caveat: You have to be sitting in the root of your "feed:" drive for this to work. The reason for this is that remove-item and move-item both look for a "Path" property on the item that gets piped through to them, and for feeds the "Path" property is a relative path from the root folder (eg. "Blogs\Mabsterama"). So the commands won't find the item to remove or move unless you're currently sitting in "feed:\".

Tuesday, January 9, 2007  |  From Mabsterama : powershell

With the new year well and truly underway, it's time to go over all those RSS feeds you're subscribed to, and clean out the ones that don't get updated any more.

But how? How could you possibly know which feeds haven't been posted to in the past, say, four months?

Why - with Windows PowerShell, of course! With a little help from the PowerShell Community Extensions and its awesome Common Feed Store provider!

So here's the command:

gci feed:\ -rec |
	?{ $_.Type -eq "Feed" } | 
	%{ $_.Items | sort -desc PubDate | select -first 1 } |
	?{ $_.PubDate -lt [DateTime]::Now.AddMonths(-4)} | 
	select @{Name="Feed" Expression={$_.Parent.Name}}, PubDate |
	ft -au

... and here's the result on my home PC:

Feed                 PubDate
----                 -------
DataWorks WebLog     12/07/2006 7:57:00 AM
Smart Client Data    9/08/2006 8:10:00 PM
What's in Store      27/06/2006 1:26:00 PM
Mick's Mix           21/08/2006 9:07:00 PM
Microsoft at Home    20/06/2006 6:00:00 PM
Microsoft at Work    9/05/2006 6:00:00 PM
Xbox World Australia 30/12/1899 12:00:00 AM
DVD Plaza            30/12/1899 12:00:00 AM
Luke Hutteman        9/01/2006 5:12:37 AM
Microsoft at Home    20/06/2006 6:00:00 PM
Microsoft at Work    9/05/2006 6:00:00 PM

Notice that a couple of those feeds have a date in 1899. That means that they don't provide a date against their posts, so they can be ignored - might as well keep hold of 'em. The rest can go! Ah ... a fresh start. :)

Tuesday, December 12, 2006  |  From Mabsterama : powershell

Here's a little one-liner to list out your all your Internet Explorer favorites:

gci $env:userprofile\favorites -rec -inc *.url |
    ? {select-string -inp $_ -quiet "^URL=http"} |
    select @{Name="Name"; Expression={[IO.Path]::GetFileNameWithoutExtension($_.FullName)}},
        @{Name="URL"; Expression={get-content $_ | ? {$_ -match "^URL=http"} | % {$_.Substring(4)}}}

Monday, December 11, 2006  |  From Mabsterama : powershell

Keith Hill has just announced the official 1.0 release of the PowerShell Community Extensions. This is a collection of handy cmdlets and functions for Windows PowerShell, and includes my provider for the Windows RSS Platform common feed store (which gives you a "feed:" drive on Vista, or if you have IE7 or Outlook 2007 installed).

Go grab it!

Tuesday, November 14, 2006  |  From Mabsterama : powershell

The official "RTW" (release to web) version of Windows PowerShell is now available! Check out the Windows PowerShell Team Blog for more details and download links.

This release is actually identical to the RC2 release, except with a new installer and licence agreement. The guys obviously did such a good job with RC2 that nothing needed to change. My FeedStoreProvider still works just fine without being recompiled or anything.

Well done, guys!

Wednesday, November 8, 2006  |  From Mabsterama : powershell

Another month and another AWDNUG meeting, and if you missed this one you should be kicking yourself.

Michael from Border Express gave an excellent presentation about SQL Server replication, breaking down the different types of replication, the pros and cons of each type, and how (and what) to monitor them. He also touched on some query optimization tips which I think were appreciated by everyone.

Did you know that if you select a table name in Sql Server Management Studio and hit Alt+F1 it dumps the table structure to the query results? I didn't either.

We had about 20 minutes left over after Michael's presentation (did I mention it was excellent?), so I gave a quick introduction to Windows PowerShell. There really wasn't enough time to touch on all the things that PowerShell is capable of, and I didn't have anything prepared, but I hope that those present got an idea of just how amazing this little command-line engine is.

The turn-out this month was less than spectacular, but I'm sure that all those who didn't attend will read this post and realised that they can't afford to miss any more meetings! See you in December, guys!

Wednesday, October 25, 2006  |  From Mabsterama : powershell

Keith and co over at the PowerShell Community Extensions project has released an alpha version, which gives you some neat new commands like "get-clipboard" and "set-filedate" in PowerShell.

The next version will include my Common Feed Store provider!

So anyway, head on over to CodePlex and download the first alpha - the guys have done a great job with the install and the cmdlets so far are worthwhile.

Monday, October 23, 2006  |  From Mabsterama : powershell

I'm going nuts coming up with new and exciting command-lines to interrogate the common feed store using my new PowerShell provider. Check this one out:

    cd feed:
    dir -rec | 
        where {$_.Author.Length -gt 0} |
        group Author |
        sort Count -desc |
        select -first 20 Name, Count |
        ft -au

That'll get you the top 20 authors across your entire feed list. Note that this is not looking for the feeds with the most items - it's the authors, so if one author posts to more than one feed then he's counted in both places. That said, in my feeds at work Robert Scoble is winning by a mile:

	Name              Count
	----              -----
	Robert Scoble       156
	Zonk                 63
	mabster              60
	Michael S. Kaplan    53
	daveburke            52
	Jason Haley          44
	Cyrus Farivar        44
	kdawson              42
	crucible             42
	Mitch Denny          40
	Leon Bambrick        36
	Paul Miller          33
	bsimser              32
	GregLow              31
	ieblog               31
	oldnewthing          31
	Long Zheng           31
	Darren Murph         30
	Carl Franklin        29
	Daniel Moth          28

Monday, October 23, 2006  |  From Mabsterama : powershell

The latest stuff I've been playing with in my PowerShell FeedStoreProvider is the ability to create and delete items within the store.

So now you can do this:

    # create a new folder called "Mad Props"
    new-item -name "Mad Props" -type folder
    # create a new feed withing that folder
    cd "Mad Props"
    new-item -name Mabsterama -type feed
        -value http://www.madprops.org/cs/blogs/mabster/rss.aspx

Similarly, "remove-item" works too. You can delete a feed or folder like this:

    remove-item Mabsterama

Next thing I want to get working is support for the "-whatif" parameter. In PowerShell you can pass "-whatif" to any command that might do something dangerous (like remove-item) and it'll inform you of what it would have done without actually doing anything. Nice.

Sunday, October 22, 2006  |  From Mabsterama : powershell

Finally worked the last annoying bug out of my FeedStoreProvider for Windows PowerShell yesterday. If you're interested, I was passing an integer as the first parameter to WriteItemObject() from within my GetChildNames override, and it was causing grief. Always pass strings from there, people!

Anyway, here's my latest trick. Want some stats about your feed subscriptions?

    cd feed:
    gci -recurse |
        where {$_ -is [Microsoft.Feeds.Interop.IFeed]} |
        Measure-Object ItemCount -sum -av -min -ma

So we're getting all the child items on my "feed:" drive recursively, filtering the list so that we're only talking about feeds and not folders or feed-items, then getting some statistics from the list. The result on my home box:

    Count    : 87
    Average  : 93.551724137931
    Sum      : 8139
    Maximum  : 200
    Minimum  : 2
    Property : ItemCount

So, I'm subscribed to 87 feeds here, with a total of 8139 items. On average, each feed has about 93 items.

Incidentally, I've added a custom parameter to "get-childitem" called "-unread", so you can, if you desire, list out only unread stuff in your subscriptions. That is, folders that contain feeds with unread items, feeds with unread items, and unread feed items. Very handy!

Friday, October 20, 2006  |  From Mabsterama : powershell

After my success yesterday in accessing the Common Feed Store from PowerShell, I started to wonder just how difficult it would be to write a provider for PowerShell so that I could access my feeds as if they were folders and files. You see, in PowerShell, you're not limited to hard drives and files when you use "dir", "cd" etc - you can change into the Windows Registry, or into the certificate store ... all sorts of places.

So I did some reading on MSDN about creating your own PowerShell providers.

A few hours later, and I can now do this:

    cd feed:
    dir -recurse |
        where {$_.Modified -gt [DateTime]::Now.AddMinutes(-90)} |
        ft Title

... which yields this output:

Title
-----
Opening & Saving Word, PowerPoint and Excel 2...
Niche Player No More;  Apple in the running f...
Where's the Cowboy Talk Now?
Open Source Music Software & The AGNULA Proje...
Zelda:Twilight Princess for GameCube NOT to b...
Old buddies reunite in hopes of taking tech w...
Fifteen Exercises for Learning a new Programm...
LOST - Further Instructions Recap

Engadget's relaunch giveaways: Slingbox PRO w...

In other words, I can list out from the command-line all the items in my feeds that have been updated in the last 90 minutes!

I'll keep working on this provider to give it more functionality. For example, right now you can't use wildcards when you type "dir", and there is no default formatting for feeds, so you need to pipe everything through to format-table to get a nice output. Still, not bad for a few hours' work!!!

Thursday, October 19, 2006  |  From Mabsterama : powershell

Oh, this is just too much fun. Check this out - a PowerShell script to display the feeds you're subscribed to (in the common RSS store you get with IE7) which have unread items:

    $feeds = (new-object -ComObject Microsoft.FeedsManager); 
    % { 
        $feeds.RootFolder.Subfolders | 
            % {$_.Feeds} | 
            select-object -pr UnreadItemCount, Title; 
        $feeds.RootFolder.Feeds | 
            select-object -pr UnreadItemCount, Title 
    } | where {$_.UnreadItemCount -gt 0} | format-table -au

I haven't found a "nice" way to combine the output of two commands into one array, but just executing both together inside a scriptblock like this appears to work.

What do you think? It's amazing the sort of stuff you can do in PowerShell!

Update! You can combine the results of two commands into a single array! Here's an updated script:

    $feeds = (new-object -ComObject Microsoft.FeedsManager); 
    @( 
        $feeds.RootFolder.Subfolders |
            % {$_.Feeds} |
            select-object -pr UnreadItemCount, Title;
        $feeds.RootFolder.Feeds | 
            select-object -pr UnreadItemCount, Title 
    ) | where {$_.UnreadItemCount -gt 0} | format-table -au

And here's the output on my machine right now:

    UnreadItemCount Title
    --------------- -----
                  4 digg
                  1 Slashdot

Wednesday, October 18, 2006  |  From Mabsterama : powershell

For the past few days I've been messing around with Windows PowerShell. PowerShell is the next-generation command-line environment for Windows and associated server products (for example, Exchange 2007 will use it as a command-line and scripting interface). It's way beyond anything you've used in a command-line in the past, because instead of passing text from command to command (via a pipeline) you're passing fully-fledged .NET objects.

Let me give you an example!

Let's say you want to know some statistics about lines of code in your source tree. The first thing you need to get is a list of C# files on your drive. No problem:

get-childitem \ -recurse -include *.cs

What are we doing here? Well, first we're using the get-childitem to recursively list every file on our hard drive with an extension of ".cs". The output of get-childitem is not a simple string of text - it's an array of System.IO.FileInfo classes.

So now we need information about the contents of each of those files. How many lines are in each file? Let's pipe our output through to another command:

dir \ -recurse -include *.cs | get-content

The get-content command returns the contents of a file as an array of strings, one for each line. We want to get the length of that array (the number of lines in the file), so let's use that get-content call in a slightly different way:

dir \ -recurse -include *.cs | 
    select-object @{Name="Lines"; Expression={(get-content $_).Length}}

The select-object command selects certain properties from the given object (in this case the FileInfo objects in the array returned by "get-childitem"). We're returning a calculated property called "Lines" which is the number of lines in the file (based on the length of the array returned by get-content).

So now our command is returning an array of Int32 values - the number of lines in every C# file on our hard drive. Last thing we want to do is get some statistics about those numbers:

dir \ -recurse -include *.cs | 
    select-object @{Name="Lines"; Expression={(get-content $_).Length}} | 
    measure-object Lines -av -sum -max -min

And we're done! The measure-object command gives us all the statistics we need. Here's an example of the output from the above string of commands:

Count : 63
Average : 221.587301587302
Sum : 13960
Maximum : 8425
Minimum : 20
Property : Lines

Pretty cool, huh? One line of commands to get a bunch of handy statistics about your lines-of-code.

This is a really simple breakdown of what's possible in PowerShell. Check out the team blog for a more in-depth look at the amazing things this thing is capable of!

 Mabsterama : powershell News Feed 

Last edited Dec 7, 2006 at 10:16 PM by codeplexadmin, version 1

Comments

No comments yet.