Showing posts with label TFS. Show all posts
Showing posts with label TFS. Show all posts

Monday, January 17, 2011

TSF + PowerShell: List all projects

This will create TFS instance and get all project from the instance.
$registryValue is an object to be displayed in the output grid of PowerGUI window.

    $tfs = get-tfs "http://TFS-URL"
    $projects = $tfs.CSS.ListAllProjects()
    
    foreach($pro in $projects) {
    $registryValue = New-Object System.Management.Automation.PSObject
    $registryValue `
        | Add-Member -Name Name -MemberType NoteProperty -Value $pro.Name -PassThru `
        | Add-Member -Name Status -MemberType NoteProperty -Value $pro.Status -PassThru `
        | Add-Member -Name URI -MemberType NoteProperty -Value $pro.Uri-PassThru `
        | Add-Member -Name BS -MemberType NoteProperty -Value $tfs.BS -PassThru

TFS + PowerShell: Create TFS instance

TFS VS 2010 and PowerShell 2

This function returns TFS instance which will be used in use cases to follow later.

function get-tfs (
    [string] $serverName = $(Throw 'serverName is required')
)
{
    # load the required dll

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

    $propertiesToAdd = (
        ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
        ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
        ('BS', 'Microsoft.TeamFoundation.Build.Client', 'Microsoft.TeamFoundation.Build.Client.IBuildServer'),
        ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
        ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
    )

    # fetch the TFS instance, but add some useful properties to make life easier
    # Make sure to "promote" it to a psobject now to make later modification easier

    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
    foreach ($entry in $propertiesToAdd) {
        $scriptBlock = '
            [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
            $this.GetService([{1}])
        ' -f $entry[1],$entry[2]
        $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
    }
    return $tfs
}


get-tfs "http://TFS-URL"

Powered by Blogger.