Automating CodePlex’s OData Service with PowerShell

by Doug Finke on April 19, 2011

in .Net,CodePlex,OData,PowerShell

The Visual Studio team just recently released the OData Service for Team Foundation Server 2010. So I whipped up some PowerShell to retrieve the ChangeSets for my CodePlex projects.

OData and PowerShell go well together, check out my OData PowerShell Explorer.

Using the .NET framework, I can download a string from an OData service using Net.WebClient. OData returns XML, this is a sweet spot for PowerShell. Using the [xml] accelerator and dot notation over the XML nodes ($result.feed.entry) makes quick work of the OData output.

Interacting with OData feeds can be automated with PowerShell

Here I am getting the change set comments for my PSCodeGen CodePlex project.

Get-CodeplexChangeSets 'TFS01' "PSCodeGen"

Get-CodePlexChangeSets creates the correct Url, queries the CodePlex OData service and returns the results as PowerShell objects ready for use and display.


I grab the Date and Comment from the ChangeSet result set, there are other fields to be mined. Be sure to check out the other details returned by CodePlex including the Builds, Changes, Builds, Branches, Work Items, Attachments, Projects, Queries and Area Paths.

From here I can easily generate release notes or filter on dates using PowerShell or analyze a range of scenarios with this data.

# Results            
TFSCollectionName Date                  ProjectName Comment                                                                                                    
----------------- ----                  ----------- -------                                                                                                    
TFS01             8/3/2010 3:44:57 PM   PSCodeGen   Checked in by server upgrade                                                                               
TFS01             6/12/2010 12:13:50 PM PSCodeGen   Cleaned up comments                                                                                        
TFS01             6/12/2010 12:02:26 PM PSCodeGen   Install-PSCodeGenerator.ps1 handles install/uninstall of vs 2010 templates                                 
TFS01             6/12/2010 9:59:40 AM  PSCodeGen   Moved the templates around                                                                                 
TFS01             6/12/2010 9:58:10 AM  PSCodeGen   Moved the directory                                                                                        
TFS01             6/12/2010 9:47:28 AM  PSCodeGen   Renamed Register-PSCodeGenerator.ps1 Install-PSCodeGenerator.ps1                                           
TFS01             6/12/2010 9:40:27 AM  PSCodeGen   Removed VB registration. Need to look into why it is correctly in the registry but does not work with VB...
TFS01             6/11/2010 2:08:49 PM  PSCodeGen                                                                                                              
TFS01             6/8/2010 9:28:26 PM   PSCodeGen                                                                                                              
TFS01             6/8/2010 9:28:13 PM   PSCodeGen                                                                                                              
TFS01             6/8/2010 9:27:22 PM   PSCodeGen   Initial import                                                                                             
TFS01             6/8/2010 8:08:20 PM   PSCodeGen   Created team project folder $/PSCodeGen via the Team Project Creation Wizard

Query Multiple CodePlex Projects in One Go

Here I setup a script to report on all my existing CodePlex projects.

    New-CodeplexProject 'TFS01' "PSCodeGen"            
    New-CodeplexProject 'TFS02' "psodata"            
    New-CodeplexProject 'TFS03' "PowerShellJSON"            
    New-CodeplexProject 'TFS05' "PoSHDebugVisualizer"            
    New-CodeplexProject 'TFS07' "pslog"            
    New-CodeplexProject 'TFS08' "trypowershell"            
    New-CodeplexProject 'TFS09' "psisecream"            
    New-CodeplexProject 'TFS07' "PowerTools"            
) | Get-CodeplexChangeSets            
# Results            
TFSCollectionName Date                   ProjectName         Comment                                                                                           
----------------- ----                   -----------         -------                                                                                           
TFS01             6/12/2010 12:13:50 PM  PSCodeGen           Cleaned up comments                                                                               
TFS01             6/12/2010 12:02:26 PM  PSCodeGen           Install-PSCodeGenerator.ps1 handles install/uninstall of vs 2010 templates                        
TFS02             8/15/2010 9:29:13 PM   psodata             Creates functions on the fly for OData Entity Types                                               
TFS02             8/15/2010 8:31:07 PM   psodata             Start spike testing reading OData metadata                                                        
TFS02             8/15/2010 8:27:42 PM   psodata             Added Chris Sells' OData service                                                                  
TFS03             4/9/2011 9:32:09 PM    PowerShellJSON      Fixed - ConvertFrom doesn't handle email addresses in the data workitem:20473 -- DCF              
TFS03             7/26/2009 11:06:54 AM  PowerShellJSON      Quick test of ConvertFrom-JSON                                                                    
TFS05             12/7/2007 8:24:53 PM   PoSHDebugVisualizer added to example program                                                                          
TFS05             12/4/2007 7:51:56 PM   PoSHDebugVisualizer change build location                                                                             
TFS07             4/20/2009 10:13:14 AM  PowerTools          Minor updates to project.                                                                         
TFS07             4/20/2009 2:15:25 AM   PowerTools          Added code to avoid image duplication. Improved Keep Sections behavior. Check for no items when...
TFS07             5/30/2010 7:39:34 PM   pslog               Added logfileName and loggerName as parameters                                                    
TFS07             5/29/2010 3:27:00 PM   pslog               Added console coloring NLog example and support                                                   
TFS08             5/1/2010 4:30:38 PM    trypowershell       Added vertical and horizontal GridSplitter, and hyperlinks are represented through hyperlinks.    
TFS08             4/26/2010 5:19:16 AM   trypowershell       KeyGesture W+Control for close added                                                              
TFS09             4/4/2010 8:54:05 AM    psisecream          This modules ISERemote requires elevated rights. Does't look nice, but the addon menu will only...
TFS09             4/3/2010 10:18:03 AM   psisecream          This is a compact module to play with PowerShell remoting.                                        

PowerShell Code

These 4 PowerShell functions make it happen.

function Get-CodePlexODataUri { "" }            
function New-CodeplexProject {            
    param (            
    New-Object PSObject -Property @{            
        TFSCollectionName = $TFSCollectionName            
        ProjectName       = $ProjectName            
function Invoke-WebClient ($url) {            
    if(!$global:Credential) {            
        $global:Credential = Get-Credential snd\'<your codeplex id here>'
    $wc = New-Object net.webclient            
    $wc.Credentials = $global:Credential             
function Get-CodeplexChangeSets  {            
    param (            
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]            
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]            
    Process {            
        $url    = Get-CodePlexODataUri            
        $url   += "$TFSCollectionName/Projects('$ProjectName')/Changesets"             
        $result = Invoke-WebClient $url            
        if($Raw) { return $result}            
        ([xml]$result).feed.entry |             
            ForEach {            
                New-Object PSObject -Property @{            
                    TFSCollectionName = $TFSCollectionName            
                    ProjectName       = $ProjectName            
                    Comment           = $_.summary.'#text'            

{ 1 trackback }

Access Team Foundation Server 2010 on Multiple Devices Using the OData Service | ITPark
05.05.11 at 9:01 pm

{ 2 comments… read them below or add one }

Peter Kriegel 03.09.12 at 2:13 am

Hi Doug!
Thank you for this Article!
I want to start a new Project on Codeplex or GitHub.
This is going to be a PowerShell module manager.
Do you know if its possible to down and upload files to codeplex with native PowerShell ?
I found only the description of the Codeplex Web Service API which seem to allow only browsing!?

Doug Finke 03.09.12 at 10:25 am

Thanks for the comment Peter.

Good question, I don’t know. That would be a great question to post on StackOverflow or email to the CodePlex team.

Looking forward to you PowerShell module manager.


Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Previous post:

Next post:

You are forbidden!