Keith Hill's Blog News Feed 
Monday, February 20, 2017  |  From Keith Hill's Blog

If  you’re looking for a bit more up-to-date getting started guide on using PowerShell with Visual Studio Code, check out these blog posts: Get started with PowerShell development in Visual Studio Code Visual Studio Code editing features for PowerShell development … Continue reading

Friday, March 11, 2016  |  From Keith Hill's Blog

We are noodling around with how to best provide support for publishing modules to the PowerShell Gallery from a PowerShell workspace within Visual Studio Code.  In today’s release of the PowerShell extension for VSCode (version 0.5.0), we have included an … Continue reading

Tuesday, March 08, 2016  |  From Keith Hill's Blog

Visual Studio Code 0.10.10 released today with many new features including indentation-based code folding and UI support for configuring “function” breakpoints.  In this blog post, I’ll show you a few new features what we have planned for the 0.5.0 release … Continue reading

Thursday, February 18, 2016  |  From Keith Hill's Blog

Writing functions that need to process paths in PowerShell and do everything that PowerShell users expect can be tricky.  Here are some of the features that folks expect for a fictitious function called “Edit-File” (well, there *is* an Edit-File command … Continue reading

Wednesday, February 10, 2016  |  From Keith Hill's Blog

There’s a new version (0.4.0) of the PowerShell extension for Visual Studio Code out with some really nice enhancements.  There’s also a new version of Visual Studio Code (0.10.8) out.  I encourage you to pick up both!  If you don’t … Continue reading

Monday, December 28, 2015  |  From Keith Hill's Blog

In this post we will look at how you can debug your PowerShell scripts using VSCode and the PowerShell Editor Services extension for VSCode.  As a pre-requisite see the post Getting Started with Visual Studio Code for Use with PowerShell … Continue reading

Sunday, December 27, 2015  |  From Keith Hill's Blog

Now that I’ve hopefully piqued your interest in using Visual Studio Code for editing and debugging PowerShell scripts, here is how you get started.  First, go to the Visual Studio code web site to download and install VSCode.  From here … Continue reading

Sunday, December 27, 2015  |  From Keith Hill's Blog

You’ve probably heard about Microsoft’s Visual Studio Code editor.  It was announced at the 2014 online Connect event.  It is a free, light-weight, cross-platform code editor supporting Windows, Linux and MacOS.  I’ve been a big fan and user of the … Continue reading

Saturday, September 12, 2015  |  From Keith Hill's Blog

If you are a fan of using Visual Studio Code as a lightweight text editor and are also a PowerShell scripter, you have probably found VS Code’s PowerShell support somewhat lacking.  For instance, while it can syntax colorize PowerShell script … Continue reading

Sunday, August 30, 2015  |  From Keith Hill's Blog

If you have ever attempted to write a little WinForms or WPF UI using PowerShell you have no doubt run across a method like add_Click() e.g. This might be a bit confusing if you are looking at C# examples or … Continue reading

Wednesday, July 29, 2015  |  From Keith Hill's Blog

When you get your shiny new Windows 10 system up and running and want to get PSCX 3.2.1 installed, just drop to the console and execute: Install-Module Pscx -Scope CurrentUser If you are running from an elevated prompt, you can … Continue reading

Monday, July 20, 2015  |  From Keith Hill's Blog

As a C and now C# developer I’ve always liked getting help with my code in the form of either Lint for C or code analysis a.k.a. FxCop for C#.  These tools are great at pointing out real and potential … Continue reading

Sunday, May 10, 2015  |  From Keith Hill's Blog

If you are running dnvm with no parameters on PowerShell with PSCX, you’re likely to see this error: 4> dnvm You must specify a command! ___ _ ___ ____ ___ / _ \/ |/ / | / / |/ / … Continue reading

Sunday, May 10, 2015  |  From Keith Hill's Blog

It looks like we will get not just the package management features PackageManagement  and PowerShellGet, but the whole of PowerShell V5 downlevel to Windows 7.  This is great news! The big features in V5 are package management, improved DSC and … Continue reading

Sunday, April 19, 2015  |  From Keith Hill's Blog

Passing this on from Microsoft. Register to attend the Microsoft MVP Virtual Conference Hi All – I wanted to let you know about a great free event that Microsoft and the MVPs are putting on, May 14th & 15th.  Join … Continue reading

Friday, January 09, 2015  |  From Keith Hill's Blog

Windows PowerShell V5, due out sometime in 2015, sports a number of new features: OneGet, PowerShell Get, enhanced DSC, ConvertFrom-String, support for authoring classes in PowerShell script, Compress/Expand-Archive, support for creating symbolic links, hard links and junctions, etc. One of … Continue reading

Saturday, November 01, 2014  |  From Keith Hill's Blog

In my last blog post, I introduced you to using .NET named pipes to implement BlackJack across different PowerShell processes and even across the network.  In this blog post, we will take a look at what it is like to … Continue reading

Saturday, November 01, 2014  |  From Keith Hill's Blog

A named pipe is a stream-based mechanism for inter-process communication (IPC).  The .NET Framework has two types for allow you to use named pipes: System.IO.Pipes.NamedPipeServerStream System.IO.Pipes.NamedPipeClientStream MSDN describes named pipes like so: Named pipes provide one-way or duplex pipes for … Continue reading

Friday, October 24, 2014  |  From Keith Hill's Blog

A new version of the PowerShell Community Extensions was released this morning on CodePlex.  PSCX 3.2.0 is also available on the PowerShell Resource Gallery Preview site which means you can use the new Install-Module command in WMF 5.0 Preview and … Continue reading

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

 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 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 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 06, 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 09, 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 09, 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 08, 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

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:

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


No comments yet.