Downloads:
4,896
Downloads of v 1.0.0.894-beta1:
389
Last Update:
06 Apr 2017
Package Maintainer(s):
Software Author(s):
- Igor Abade V. Leite
Tags:
tfscmdlets tfs vsts powershell- Software Specific:
- Software Site
- Software License
- Package Specific:
- Possible Package Source
- Package outdated?
- Package broken?
- Contact Maintainers
- Contact Site Admins
- Software Vendor?
- Report Abuse
- Download
TfsCmdlets
This is a prerelease version of TfsCmdlets.
- 1
- 2
- 3
1.0.0.894-beta1 | Updated: 06 Apr 2017
- Software Specific:
- Software Site
- Software License
- Package Specific:
- Possible Package Source
- Package outdated?
- Package broken?
- Contact Maintainers
- Contact Site Admins
- Software Vendor?
- Report Abuse
- Download
Downloads:
4,896
Downloads of v 1.0.0.894-beta1:
389
Maintainer(s):
Software Author(s):
- Igor Abade V. Leite
TfsCmdlets 1.0.0.894-beta1
This is a prerelease version of TfsCmdlets.
Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by Igor Abade V. Leite. The inclusion of Igor Abade V. Leite trademark(s), if any, upon this webpage is solely to identify Igor Abade V. Leite goods or services and not for commercial purposes.
- 1
- 2
- 3
All Checks are Passing
3 Passing Tests
Deployment Method: Individual Install, Upgrade, & Uninstall
To install TfsCmdlets, run the following command from the command line or from PowerShell:
To upgrade TfsCmdlets, run the following command from the command line or from PowerShell:
To uninstall TfsCmdlets, run the following command from the command line or from PowerShell:
Deployment Method:
This applies to both open source and commercial editions of Chocolatey.
1. Enter Your Internal Repository Url
(this should look similar to https://community.chocolatey.org/api/v2/)
2. Setup Your Environment
1. Ensure you are set for organizational deployment
Please see the organizational deployment guide
2. Get the package into your environment
Option 1: Cached Package (Unreliable, Requires Internet - Same As Community)-
Open Source or Commercial:
- Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
- You can also just download the package and push it to a repository Download
-
Open Source
-
Download the package:
Download - Follow manual internalization instructions
-
-
Package Internalizer (C4B)
-
Run: (additional options)
choco download tfscmdlets --internalize --version=1.0.0.894-beta1 --pre --source=https://community.chocolatey.org/api/v2/
-
For package and dependencies run:
choco push --source="'INTERNAL REPO URL'"
- Automate package internalization
-
Run: (additional options)
3. Copy Your Script
choco upgrade tfscmdlets -y --source="'INTERNAL REPO URL'" --version="'1.0.0.894-beta1'" --prerelease [other options]
See options you can pass to upgrade.
See best practices for scripting.
Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.
If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:
choco upgrade tfscmdlets -y --source="'INTERNAL REPO URL'" --version="'1.0.0.894-beta1'" --prerelease
$exitCode = $LASTEXITCODE
Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
Exit 0
}
Exit $exitCode
- name: Install tfscmdlets
win_chocolatey:
name: tfscmdlets
version: '1.0.0.894-beta1'
source: INTERNAL REPO URL
state: present
allow_prerelease: yes
See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.
chocolatey_package 'tfscmdlets' do
action :install
source 'INTERNAL REPO URL'
version '1.0.0.894-beta1'
options '--prerelease'
end
See docs at https://docs.chef.io/resource_chocolatey_package.html.
cChocoPackageInstaller tfscmdlets
{
Name = "tfscmdlets"
Version = "1.0.0.894-beta1"
Source = "INTERNAL REPO URL"
chocoParams = "--prerelease"
}
Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.
package { 'tfscmdlets':
ensure => '1.0.0.894-beta1',
install_options => ['--prerelease'],
provider => 'chocolatey',
source => 'INTERNAL REPO URL',
}
Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.
4. If applicable - Chocolatey configuration/installation
See infrastructure management matrix for Chocolatey configuration elements and examples.
This package is exempt from moderation. While it is likely safe for you, there is more risk involved.
PowerShell Cmdlets for TFS and VSTS
Function Test-RegistryValue
{
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Path,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Value
)
Process
{
try
{
Get-RegistryValue -Path $Path -Value $Value | Out-Null
return $true
}
catch {}
return $false
}
}
Function Get-RegistryValue
{
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Path,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Value
)
Process
{
return Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value
}
}
Function New-ScriptBlock($EntryPoint, [string[]]$Dependency)
{
$entryPoint = (Get-Item "function:$EntryPoint").Definition.Trim()
$paramSection = $entryPoint.Substring(0, $entryPoint.IndexOf("`n"))
$bodySection = $entryPoint.Substring($paramSection.Length) + "`n`n"
$body = $paramSection
foreach($depFn in $Dependency)
{
$f = Get-Item "function:$depFn"
$body += "Function $f `n{`n"
$body += $f.Definition
$body += "`n}`n`n"
}
$body += $bodySection
return [scriptblock]::Create($body)
}
Function Invoke-ScriptBlock($ScriptBlock, $Computer, $Credentials, $ArgumentList)
{
if (-not $Computer)
{
return Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $ArgumentList
}
elseif ($Computer -is [System.Management.Automation.Runspaces.PSSession])
{
return Invoke-Command -ScriptBlock $scriptBlock -Session $Computer -ArgumentList $ArgumentList
}
return Invoke-Command -ScriptBlock $scriptBlock -ComputerName $Computer -Credential $Credential -ArgumentList $ArgumentList
}
<#
.SYNOPSIS
Gets the installation path of a given Team Foundation Server component.
.PARAMETER Computer
The machine name of the server where the TFS component is installed. It must be properly configured for PowerShell Remoting in case it's a remote machine. If omitted, defaults to the local machine where the script is being run.
Optionally, a System.Management.Automation.Runspaces.PSSession object pointing to a previously opened PowerShell Remote session can be provided instead.
.PARAMETER Component
Indicates the TFS component whose installation path is being searched for. For the main TFS installation directory, use BaseInstallation.
.PARAMETER Version
The TFS version number, in the format '##.#'. For TFS 2015, use '14.0'
.PARAMETER Credential
The user credentials to be used to access a remote machine. Those credentials must have the required permission to execute a PowerShell Remote session on that computer and also the permission to access the Windows Registry.
#>
Function Get-TfsInstallationPath
{
[CmdletBinding()]
[OutputType([string])]
Param
(
[Parameter()]
[object]
[Alias('Session')]
$Computer,
[Parameter()]
[ValidateSet('BaseInstallation', 'ApplicationTier', 'SharePointExtensions', 'TeamBuild', 'Tools', 'VersionControlProxy')]
[string]
$Component = 'BaseInstallation',
[Parameter(Mandatory=$true)]
[ValidateSet('11.0','12.0','14.0','15.0')]
[string]
$Version,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$scriptBlock = New-ScriptBlock -EntryPoint '_GetInstallationPath' -Dependency 'Test-RegistryValue', 'Get-RegistryValue'
return Invoke-ScriptBlock -ScriptBlock $scriptBlock -Computer $Computer -Credential $Credential -ArgumentList $Version, $Component
}
}
Function _GetInstallationPath($Version, $Component)
{
$rootKeyPath = "HKLM:\Software\Microsoft\TeamFoundationServer\$Version"
if ($Component -eq 'BaseInstallation')
{
$componentPath = $rootKeyPath
}
else
{
$componentPath = "$rootKeyPath\InstalledComponents\$Component"
}
if (-not (Test-RegistryValue -Path $rootKeyPath -Value 'InstallPath'))
{
throw "Team Foundation Server is not installed in computer $env:COMPUTERNAME"
}
if (-not (Test-RegistryValue -Path $componentPath -Value 'InstallPath'))
{
throw "Team Foundation Server component '$Component' is not installed in computer $env:COMPUTERNAME"
}
return Get-RegistryValue -Path $componentPath -Value 'InstallPath'
}
Function _GetCssNodes($Node, $Scope, $Project, $Collection)
{
Process
{
if ($Node -is [Microsoft.TeamFoundation.Server.NodeInfo])
{
return $Node
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$projectName = $tp.Name
$cssService = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.ICommonStructureService")
if ($node -is [uri])
{
return $cssService.GetNode($node)
}
$rootPath = _NormalizePath "$projectName\$Scope"
$fullPath = _NormalizePath "$rootPath\$Node"
$rootNodeUri = $cssService.GetNodeFromPath("$rootPath").Uri
$rootElement = $cssService.GetNodesXml(@($rootNodeUri), $true)
$nodePaths = $rootElement.SelectNodes('//@Path') | Select -ExpandProperty '#text'
$matchingPaths = $nodePaths | ? { $_ -like $fullPath }
return $matchingPaths | % { $cssService.GetNodeFromPath($_) }
}
}
Function _DeleteCssNode($Node, $Scope, $MoveToNode, $Project, $Collection)
{
Process
{
$newNode = _GetCssNodes -Node $MoveToNode -Scope $Scope -Project $Project -Collection $Collection
$cssService = _GetCssService -Project $Project -Collection $Collection
$cssService.DeleteBranches($Node.Uri, $newNode.Uri)
}
}
Function _NewCssNode ($Project, $Path, $Scope, $Collection, $StartDate, $FinishDate)
{
Process
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$projectName = $tp.Name
$cssService = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.ICommonStructureService")
try
{
$fullPath = _NormalizePath "$projectName\$Scope\$Path"
$parentPath = Split-Path $fullPath -Parent
$nodeName = Split-Path $fullPath -Leaf
$parentNode = $cssService.GetNodeFromPath($parentPath)
}
catch
{
$parentNode = _NewCssNode -Project $Project -Path $parentPath -Scope $Scope -Collection $Collection
}
if ($StartDate -or $FinishDate)
{
$cssService = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.ICommonStructureService4")
$nodeUri = $cssService.CreateNode($nodeName, $parentNode.Uri, $StartDate, $FinishDate)
}
else
{
$nodeUri = $cssService.CreateNode($nodeName, $parentNode.Uri)
}
return $cssService.GetNode($nodeUri)
}
}
Function _NormalizePath($Path)
{
if([string]::IsNullOrWhiteSpace($Path))
{
return [string]::Empty
}
$newPath = [System.Text.RegularExpressions.Regex]::Replace($Path, '\\{2,}', '\')
if (-not $newPath.StartsWith("\"))
{
$newPath = "\$newPath"
}
if ($newPath.EndsWith("\"))
{
$newPath = $newPath.Substring(0, $newPath.Length-1)
}
return $newPath
}
Function _GetCssService($Project, $Collection, $Version)
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$projectName = $tp.Name
return $tpc.GetService([type]"Microsoft.TeamFoundation.Server.ICommonStructureService$Version")
}
<#
.SYNOPSIS
Gets one or more Work Item Areas from a given Team Project.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsArea
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Position=0)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[SupportsWildcards()]
[object]
$Area = '\**',
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
return _GetCssNodes -Node $Area -Scope Area -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Gets one or more Work Item Iterations from a given Team Project.
.PARAMETER Iteration
Specifies the name, URI or path of an Iteration. Wildcards are permitted. If omitted, all Iterations in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node).
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsIteration
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Position=0)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[SupportsWildcards()]
[object]
$Iteration = '\**',
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
return _GetCssNodes -Node $Iteration -Scope Iteration -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Moves a Work Item Area from its parent area to another one in the same Team Project.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER Destination
Specifies the name, URI or path of an Area Path that will become the new parent of the given source area
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Server.NodeInfo
System.String
System.Uri
#>
Function Move-TfsArea
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Area,
[Parameter(Position=1l)]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Destination,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$node = Get-TfsArea -Area $Area -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent area $Area"
}
$destinationNode = Get-TfsArea -Area $Destination -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent destination area $Destination"
}
$cssService = _GetCssService -Project $Project -Collection $Collection
$cssService.MoveBranch($node.Uri, $destinationNode.Uri)
return $cssService.GetNode($node.Uri)
}
}
<#
.SYNOPSIS
Moves a Work Item Iteration from its parent iteration to another one in the same Team Project.
.PARAMETER Iteration
Specifies the name, URI or path of an Iteration. Wildcards are permitted. If omitted, all Iterations in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node).
.PARAMETER Destination
Specifies the name, URI or path of an Iteration Path that will become the new parent of the given source iteration
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Server.NodeInfo
System.String
System.Uri
#>
Function Move-TfsIteration
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Iteration,
[Parameter(Position=1)]
[ValidateScript({($_ -is [string]) -or ($_ -is [uri]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Destination,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$node = Get-TfsIteration -Iteration $Iteration -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent iteration $Iteration"
}
$destinationNode = Get-TfsIteration -Iteration $Destination -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent destination iteration $Destination"
}
$cssService = _GetCssService -Project $Project -Collection $Collection
$cssService.MoveBranch($node.Uri, $destinationNode.Uri)
return $cssService.GetNode($node.Uri)
}
}
<#
.SYNOPSIS
Creates a new Work Item Area in the given Team Project.
.PARAMETER Area
Specifies the path of the new Area. When supplying a path, use a backslash ("\") between the path segments. Leading and trailing backslashes are optional. The last segment in the path will be the area name.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function New-TfsArea
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[string]
$Area,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
return _NewCssNode -Path $Area -Scope Area -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Creates a new Work Item Iteration in the given Team Project.
.PARAMETER Iteration
Specifies the path of the new Iteration. When supplying a path, use a backslash ("\") between the path segments. Leading and trailing backslashes are optional. The last segment in the path will be the iteration name.
.PARAMETER StartDate
Specifies the start of a timed iteration, such as a sprint. Enter a string that represents the date and time, such as "12/01/2015" or a DateTime object, such as one from a Get-Date command. When omitted, no start date is set.
.PARAMETER FinishDate
Specifies the end of a timed iteration, such as a sprint. Enter a string that represents the date and time, such as "12/01/2015" or a DateTime object, such as one from a Get-Date command. When omitted, no finish date is set.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function New-TfsIteration
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[string]
$Iteration,
[Parameter()]
[DateTime]
$StartDate,
[Parameter()]
[DateTime]
$FinishDate,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
return _NewCssNode -Path $Iteration -Scope Iteration -Project $Project -Collection $Collection -StartDate $StartDate -FinishDate $FinishDate
}
}
<#
.SYNOPSIS
Deletes one or more Work Item Areas.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER MoveTo
Specifies the new area path for the work items currently assigned to the area being deleted, if any. When omitted, defaults to the root area
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Remove-TfsArea
{
[CmdletBinding(ConfirmImpact='High', SupportsShouldProcess=$true)]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Area,
[Parameter(Position=1)]
[Alias("NewPath")]
[ValidateScript({ ($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo]) })]
[object]
$MoveTo = '\',
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$Areas = Get-TfsArea -Area $Area -Project $Project -Collection $Collection | Sort -Property Path -Descending
foreach($i in $Areas)
{
if ($PSCmdlet.ShouldProcess($i.RelativePath, "Delete Area"))
{
$projectName = $i.Path.Split("\")[1]
_DeleteCssNode -Node $i -MoveToNode $MoveTo -Scope Area -Project $projectName -Collection $Collection
}
}
}
}
<#
.SYNOPSIS
Deletes one or more Work Item Iterations.
.PARAMETER Iteration
Specifies the name, URI or path of an Iteration. Wildcards are permitted. If omitted, all Iterations in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node).
.PARAMETER MoveTo
Specifies the new iteration path for the work items currently assigned to the iteration being deleted, if any. When omitted, defaults to the root iteration
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Remove-TfsIteration
{
[CmdletBinding(ConfirmImpact='High', SupportsShouldProcess=$true)]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Iteration,
[Parameter(Position=1)]
[Alias("NewPath")]
[ValidateScript({ ($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo]) })]
[object]
$MoveTo = '\',
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$iterations = Get-TfsIteration -Iteration $Iteration -Project $Project -Collection $Collection | Sort -Property Path -Descending
foreach($i in $iterations)
{
if ($PSCmdlet.ShouldProcess($i.RelativePath, "Delete Iteration"))
{
$projectName = $i.Path.Split("\")[1]
_DeleteCssNode -Node $i -MoveToNode $MoveTo -Scope Iteration -Project $Project -Collection $Collection
}
}
}
}
<#
.SYNOPSIS
Renames a Work Item Area.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER NewName
Specifies the new name of the area. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the Area parameter, Rename-TfsArea generates an error. To rename and move an item, use the Move-TfsArea cmdlet.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Rename-TfsArea
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[Alias("Path")]
[object]
$Area,
[Parameter(Position=1)]
[string]
$NewName,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
Set-TfsArea -Area $Area -NewName $NewName -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Renames a Work Item Iteration.
.PARAMETER Iteration
Specifies the name, URI or path of an Iteration. Wildcards are permitted. If omitted, all Iterations in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node).
.PARAMETER NewName
Specifies the new name of the iteration. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the Iteration parameter, Rename-TfsIteration generates an error. To rename and move an item, use the Move-TfsIteration cmdlet.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Rename-TfsIteration
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[Alias("Path")]
[object]
$Iteration,
[Parameter(Position=1)]
[string]
$NewName,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
Set-TfsIteration -Iteration $Iteration -NewName $NewName -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Modifies the name and/or the position of a Work Item Area.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER NewName
Specifies the new name of the area. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the area parameter, Rename-Tfsarea generates an error. To rename and move an item, use the Move-Tfsarea cmdlet.
.PARAMETER MoveBy
Reorders an area by moving it either up or down inside its parent. A positive value moves an area down, whereas a negative one moves it up.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Set-TfsArea
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[Alias("Path")]
[object]
$Area,
[Parameter()]
[string]
$NewName,
[Parameter()]
[int]
$MoveBy,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$node = Get-TfsArea -Area $Area -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent area $Area"
}
$cssService = _GetCssService -Project $Project -Collection $Collection
if ($NewName)
{
$cssService.RenameNode($node.Uri, $NewName)
}
if ($MoveBy)
{
$cssService.ReorderNode($node.Uri, $MoveBy)
}
return $cssService.GetNode($node.Uri)
}
}
<#
.SYNOPSIS
Modifies the name, position and/or the dates of a Work Item Iteration.
.PARAMETER Iteration
Specifies the name, URI or path of an Iteration. Wildcards are permitted. If omitted, all Iterations in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node).
.PARAMETER NewName
Specifies the new name of the iteration. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the Iteration parameter, Rename-TfsIteration generates an error. To rename and move an item, use the Move-TfsIteration cmdlet.
.PARAMETER MoveBy
Reorders an iteration by moving it either up or down inside its parent. A positive value moves an iteration down, whereas a negative one moves it up.
.PARAMETER StartDate
Sets the start date of the iteration. To clear the start date, set it to $null. Note that when clearing a date, both must be cleared at the same time (i.e. setting both StartDate and FinishDate to $null)
.PARAMETER FinishDate
Sets the finish date of the iteration. To clear the finish date, set it to $null. Note that when clearing a date, both must be cleared at the same time (i.e. setting both StartDate and FinishDate to $null)
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Set-TfsIteration
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.NodeInfo])]
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Server.NodeInfo])})]
[object]
$Iteration = '\**',
[Parameter()]
[string]
$NewName,
[Parameter()]
[int]
$MoveBy,
[Parameter()]
[Nullable[DateTime]]
$StartDate,
[Parameter()]
[Nullable[DateTime]]
$FinishDate,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$node = Get-TfsIteration -Iteration $Iteration -Project $Project -Collection $Collection
if (-not $node)
{
throw "Invalid or non-existent iteration $Iteration"
}
$cssService = _GetCssService -Project $Project -Collection $Collection
$cssService4 = _GetCssService -Project $Project -Collection $Collection -Version 4
if ($NewName)
{
$cssService.RenameNode($node.Uri, $NewName)
}
if ($MoveBy)
{
$cssService.ReorderNode($node.Uri, $MoveBy)
}
if ($StartDate -or $FinishDate)
{
if (-not $PSBoundParameters.ContainsKey("StartDate"))
{
$StartDate = $node.StartDate
}
if (-not $PSBoundParameters.ContainsKey("FinishDate"))
{
$FinishDate = $node.FinishDate
}
[void]$cssService4.SetIterationDates($node.Uri, $StartDate, $FinishDate)
}
return $cssService.GetNode($node.Uri)
}
}
$InstallPath = Join-Path $($env:ChocolateyInstall) 'lib\TfsCmdlets'
$ToolsDir = Join-Path $InstallPath 'Tools'
if ($env:PSModulePath -like "*$ToolsDir*")
{
Write-Output "TfsCmdlets: Removing installation directory from PSModulePath environment variable"
$NewModulePath = $Env:PSModulePath.Replace($ToolsDir, '').Replace(';;', ';')
SETX @('PSModulePath', $NewModulePath, '/M')
}
$ShortcutTargetDir = "$Env:ProgramData\Microsoft\Windows\Start Menu\Programs"
$ShortcutName = 'Team Foundation Server Shell'
$ShortcutFilePath = "$ShortcutTargetDir\$ShortcutName.lnk"
if (Test-Path $ShortcutFilePath)
{
Write-Output "TfsCmdlets: Removing Start Menu shortcut file"
Remove-Item $ShortcutFilePath
}
<#
.SYNOPSIS
Gets information about a configuration server.
.PARAMETER Server
Specifies either a URL/name of the Team Foundation Server to connect to, or a previously initialized TfsConfigurationServer object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Foundation Server instance by using its name, it must have been previously registered.
.PARAMETER Current
Returns the configuration server specified in the last call to Connect-TfsConfigurationServer (i.e. the "current" configuration server)
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.INPUTS
Microsoft.TeamFoundation.Client.TfsConfigurationServer
System.String
System.Uri
#>
Function Get-TfsConfigurationServer
{
[CmdletBinding(DefaultParameterSetName='Get by server')]
[OutputType([Microsoft.TeamFoundation.Client.TfsConfigurationServer])]
Param
(
[Parameter(Position=0, ParameterSetName='Get by server', Mandatory=$true, ValueFromPipeline=$true)]
[AllowNull()]
[object]
$Server,
[Parameter(Position=0, ParameterSetName="Get current")]
[switch]
$Current,
[Parameter(Position=1, ParameterSetName='Get by server')]
[object]
$Credential
)
Process
{
if ($Current)
{
return $Global:TfsServerConnection
}
if ($Server -is [Microsoft.TeamFoundation.Client.TfsConfigurationServer])
{
return $Server
}
if ($Server -is [Uri])
{
return _GetConfigServerFromUrl $Server $Credential
}
if ($Server -is [string])
{
if ([Uri]::IsWellFormedUriString($Server, [UriKind]::Absolute))
{
return _GetConfigServerFromUrl ([Uri] $Server) $Credential
}
if (-not [string]::IsNullOrWhiteSpace($Server))
{
return _GetConfigServerFromName $Server $Credential
}
}
if ($Server -eq $null)
{
if ($Global:TfsServerConnection)
{
return $Global:TfsServerConnection
}
}
throw "No TFS connection information available. Either supply a valid -Server argument or use Connect-TfsConfigurationServer prior to invoking this cmdlet."
}
}
# =================
# Helper Functions
# =================
Function _GetConfigServerFromUrl([uri] $Url, $Credential)
{
$cred = Get-TfsCredential -Credential $Credential
return New-Object Microsoft.TeamFoundation.Client.TfsConfigurationServer -ArgumentList ([Uri] $Url), $cred
}
Function _GetConfigServerFromName($Name, $Credential)
{
$Servers = Get-TfsRegisteredConfigurationServer $Name
foreach($Server in $Servers)
{
$Url = $Server.Uri
$cred = Get-TfsCredential -Credential $Credential
$configServer = New-Object Microsoft.TeamFoundation.Client.TfsConfigurationServer -ArgumentList $Url, $cred
$configServer.EnsureAuthenticated()
Write-Output $configServer
}
}
<#
.SYNOPSIS
Gets the configuration server database connection string.
.PARAMETER Computer
Specifies the name of a Team Foundation Server application tier from which to retrieve the connection string
.PARAMETER Version
Specifies the version of the Team Foundation Server being queried. Valid values are '12.0' (TFS 2013), '14.0' (TFS 2015), '15.0' (TFS 2017)
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
#>
Function Get-TfsConfigurationServerConnectionString
{
[CmdletBinding()]
[OutputType([string])]
Param
(
[Parameter()]
[string]
[Alias('Session')]
$Computer,
[Parameter()]
[ValidateSet('12.0', '14.0', '15.0')]
[string]
$Version,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$scriptBlock = New-ScriptBlock -EntryPoint '_GetConnectionString' -Dependency 'Get-InstallationPath', 'Test-RegistryValue', 'Get-RegistryValue'
return Invoke-ScriptBlock -ScriptBlock $scriptBlock -Computer $Computer -Credential $Credential -ArgumentList $Version
}
}
Function _GetConnectionString($Version)
{
$path = Get-InstallationPath -Version $Version -Component ApplicationTier
$webConfigPath = Join-Path $path 'Web Services\Web.config'
$webConfig = [xml] (Get-Content $webConfigPath)
return (Select-Xml -Xml $webConfig -XPath '/configuration/appSettings/add[@key="applicationDatabase"]/@value').Node.Value
}
<#
.SYNOPSIS
Gets one or more Team Foundation Server addresses registered in the current computer.
.PARAMETER Name
Specifies the name of a registered server. When omitted, all registered servers are returned. Wildcards are permitted.
.INPUTS
System.String
#>
Function Get-TfsRegisteredConfigurationServer
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Client.RegisteredConfigurationServer])]
Param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[string]
$Name = "*"
)
Process
{
if(($Name -eq "localhost") -or ($Name -eq "."))
{
$Name = $env:COMPUTERNAME
}
return [Microsoft.TeamFoundation.Client.RegisteredTfsConnections]::GetConfigurationServers() | ? Name -Like $Name
}
}
<#
.SYNOPSIS
Connects to a configuration server.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
.DESCRIPTION
The Connect-TfsConfigurationServer function connects to a TFS configuration server. Functions that operate on a server level (as opposed to those operation on a team project collection level) will use by default a connection opened by this function.
.NOTES
A TFS Configuration Server represents the server that is running Team Foundation Server. On a database level, it is represented by the Tfs_Configuration database. Operations that should be performed on a server level (such as setting server-level permissions) require a connection to a TFS configuration server. Internally, this connection is represented by an instance of the Microsoft.TeamFoundation.Client.TfsConfigurationServer class and is kept in a PowerShell global variable caled TfsServerConnection .
.PARAMETER Interactive
Prompts for user credentials. Can be used for both TFS and VSTS accounts - the proper login dialog is automatically selected. Should only be used in an interactive PowerShell session (i.e., a PowerShell terminal window), never in an unattended script (such as those executed during an automated build).
.INPUTS
Microsoft.TeamFoundation.Client.TfsConfigurationServer
System.String
System.Uri
#>
Function Connect-TfsConfigurationServer
{
[CmdletBinding(DefaultParameterSetName="Explicit credentials")]
[OutputType([Microsoft.TeamFoundation.Client.TfsConfigurationServer])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNull()]
[object]
$Server,
[Parameter(ParameterSetName="Explicit credentials")]
[object]
$Credential,
[Parameter(ParameterSetName="Prompt for credentials", Mandatory=$true)]
[switch]
$Interactive,
[Parameter()]
[switch]
$Passthru
)
Process
{
if ($Interactive.IsPresent)
{
$Credential = (Get-TfsCredential -Interactive)
}
$configServer = Get-TfsConfigurationServer -Server $Server -Credential $Credential
if (-not $configServer)
{
throw "Error connecting to TFS"
}
$Global:TfsTeamConnection = $null
$Global:TfsProjectConnection = $null
$Global:TfsTpcConnection = $null
$Global:TfsServerConnection = $configServer
if ($Passthru)
{
return $configServer
}
}
}
<#
.SYNOPSIS
Connects to a team project.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.PARAMETER Interactive
Prompts for user credentials. Can be used for both TFS and VSTS accounts - the proper login dialog is automatically selected. Should only be used in an interactive PowerShell session (i.e., a PowerShell terminal window), never in an unattended script (such as those executed during an automated build).
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
#>
Function Connect-TfsTeamProject
{
[CmdletBinding(DefaultParameterSetName="Explicit credentials")]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.Project])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNull()]
[object]
$Project,
[Parameter()]
[object]
$Collection,
[Parameter(ParameterSetName="Explicit credentials")]
[object]
$Credential,
[Parameter(ParameterSetName="Prompt for credentials", Mandatory=$true)]
[switch]
$Interactive,
[Parameter()]
[switch]
$Passthru
)
Process
{
if ($Interactive.IsPresent)
{
$Credential = (Get-TfsCredential -Interactive)
}
$tp = (Get-TfsTeamProject -Project $Project -Collection $Collection -Credential $Credential | Select -First 1)
if (-not $tp)
{
throw "Error connecting to team project $Project"
}
$Global:TfsTeamConnection = $null
$Global:TfsProjectConnection = $tp
$Global:TfsTpcConnection = $tp.Store.TeamProjectCollection
$Global:TfsServerConnection = $Global:TfsTpcConnection.ConfigurationServer
if ($Passthru)
{
return $tp
}
}
}
<#
.SYNOPSIS
Connects to a team project collection.
.DESCRIPTION
The Connect-TfsTeamProjectCollection cmdlet "connects" (initializes a Microsoft.TeamFoundation.Client.TfsTeamProjectCollection object) to a TFS Team Project Collection. That connection is subsequently kept in a global variable to be later reused until it's closed by a call to Disconnect-TfsTeamProjectCollection.
Most cmdlets in the TfsCmdlets module require a TfsTeamProjectCollection object to be provided via their -Collection argument in order to access a TFS instance. Those cmdlets will use the connection opened by Connect-TfsTeamProjectCollection as their "default connection". In other words, TFS cmdlets (e.g. New-TfsWorkItem) that have a -Collection argument will use the connection provided by Connect-TfsTeamProjectCollection by default.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When a TfsTeamProjectCollection object is provided via this argument, it will be used as the new default connection. This may be especially useful if you e.g. received a pre-initialized connection to a TFS collection via a call to an external library or API.
For more details, see the -Collection argument in the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Server
Specifies either a URL or the name of the Team Foundation Server configuration server (the "root" of a TFS installation) to connect to, or a previously initialized Microsoft.TeamFoundation.Client.TfsConfigurationServer object.
For more details, see the -Server argument in the Get-TfsConfigurationServer cmdlet.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.PARAMETER Interactive
Prompts for user credentials. Can be used for both TFS and VSTS accounts - the proper login dialog is automatically selected. Should only be used in an interactive PowerShell session (i.e., a PowerShell terminal window), never in an unattended script (such as those executed during an automated build).
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
.EXAMPLE
Connect-TfsTeamProjectCollection -Collection http://tfs:8080/tfs/DefaultCollection
Connects to a collection called "DefaultCollection" in a TF server called "tfs" using the default credentials of the logged-on user
.EXAMPLE
Connect-TfsTeamProjectCollection -Collection http://tfs:8080/tfs/DefaultCollection -Interactive
Connects to a collection called "DefaultCollection" in a Team Foundation server called "tfs", firstly prompting the user for credentials (it ignores the cached credentials for the currently logged-in user). It's equivalent to the command:
PS> Connect-TfsTeamProjectCollection -Collection http://tfs:8080/tfs/DefaultCollection -Credential (Get-TfsCredential -Interactive)
.LINK
Get-TfsTeamProjectCollection
.LINK
https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsteamprojectcollection.aspx
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Connect-TfsTeamProjectCollection
{
[CmdletBinding(DefaultParameterSetName="Explicit credentials")]
[OutputType([Microsoft.TeamFoundation.Client.TfsTeamProjectCollection])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNull()]
[object]
$Collection,
[Parameter()]
[object]
$Server,
[Parameter(ParameterSetName="Explicit credentials")]
[object]
$Credential,
[Parameter(ParameterSetName="Prompt for credentials", Mandatory=$true)]
[switch]
$Interactive,
[Parameter()]
[switch]
$Passthru
)
Process
{
$tpc = $null
try
{
if ($Interactive.IsPresent)
{
$Credential = (Get-TfsCredential -Interactive)
}
$tpc = (Get-TfsTeamProjectCollection -Collection $Collection -Server $Server -Credential $Credential | Select -First 1)
$tpc.EnsureAuthenticated()
}
catch
{
throw "Error connecting to team project collection $Collection ($_)"
}
$Global:TfsTeamConnection = $null
$Global:TfsProjectConnection = $null
$Global:TfsTpcConnection = $tpc
$Global:TfsServerConnection = $tpc.ConfigurationServer
if ($Passthru)
{
return $tpc
}
}
}
<#
.SYNOPSIS
Disconnects from the currently connected configuration server.
.DESCRIPTION
The Disconnect-TfsConfigurationServer cmdlet removes the global variable set by Connect-TfsConfigurationServer. Therefore, cmdlets relying on a "default server" as provided by "Get-TfsConfigurationServer -Current" will no longer work after a call to this cmdlet, unless their -Server argument is provided or a new call to Connect-TfsConfigurationServer is made.
.EXAMPLE
Disconnect-TfsConfigurationServer
Disconnects from the currently connected TFS configuration server
#>
Function Disconnect-TfsConfigurationServer
{
Process
{
Disconnect-TfsTeamProjectCollection
if ($Global:TfsServerConnection)
{
Remove-Variable -Name TfsServerConnection -Scope Global
}
}
}
<#
.SYNOPSIS
Disconnects from the currently connected team project.
.DESCRIPTION
The Disconnect-TfsTeamProject cmdlet removes the global variable set by Connect-TfsTeamProject . Therefore, cmdlets relying on a "default project" as provided by "Get-TfsTeamProject -Current" will no longer work after a call to this cmdlet, unless their -Project argument is provided or a new call to Connect-TfsTeamProject is made.
.EXAMPLE
Disconnect-TfsTeamProject
Disconnects from the currently connected TFS team project
#>
Function Disconnect-TfsTeamProject
{
Process
{
if ($Global:TfsProjectConnection)
{
Remove-Variable -Name TfsProjectConnection -Scope Global
}
}
}
<#
.SYNOPSIS
Disconnects from the currently connected team project collection.
.DESCRIPTION
The Disconnect-TfsTeamProjectCollection cmdlet removes the global variable set by Connect-TfsTeamProjectCollection. Therefore, cmdlets relying on a "default collection" as provided by "Get-TfsTeamProjectCollection -Current" will no longer work after a call to this cmdlet, unless their -Collection argument is provided or a new call to Connect-TfsTeamProjectCollection is made.
.EXAMPLE
Disconnect-TfsTeamProjectCollection
Disconnects from the currently connected TFS team project collection
#>
Function Disconnect-TfsTeamProjectCollection
{
Process
{
Disconnect-TfsTeamProject
if ($Global:TfsTpcConnection)
{
Remove-Variable -Name TfsTpcConnection -Scope Global
}
}
}
<#
.SYNOPSIS
Provides credentials to use when you connect to a Team Foundation Server or Visual Studio Team Services account.
.DESCRIPTION
.NOTES
.INPUTS
#>
Function Get-TfsCredential
{
[CmdletBinding(DefaultParameterSetName="Prompt for credential")]
[OutputType([Microsoft.TeamFoundation.Client.TfsClientCredentials])]
Param
(
[Parameter(ParameterSetName="Cached Credential", Mandatory=$true)]
[switch]
$Cached,
[Parameter(ParameterSetName="User name and password", Mandatory=$true, Position=1)]
[string]
$UserName,
[Parameter(ParameterSetName="User name and password", Position=2)]
[securestring]
$Password,
[Parameter(ParameterSetName="Credential object")]
[object]
$Credential,
[Parameter(ParameterSetName="Personal Access Token")]
[Alias('Pat')]
$PersonalAccessToken,
[Parameter(ParameterSetName="Prompt for credential")]
[switch]
$Interactive
)
Process
{
$parameterSetName = $PSCmdlet.ParameterSetName
if (($parameterSetName -eq 'Credential object') -and (-not $Credential))
{
$parameterSetName = 'Cached Credential'
}
$allowInteractive = $false
switch($parameterSetName)
{
'Cached Credential' {
$fedCred = New-Object 'Microsoft.TeamFoundation.Client.CookieCredential' -ArgumentList $true
$winCred = New-Object 'Microsoft.TeamFoundation.Client.WindowsCredential' -ArgumentList $true
}
'User name and password' {
$netCred = New-Object 'System.Net.NetworkCredential' -ArgumentList $UserName, $Password
$fedCred = New-Object 'Microsoft.TeamFoundation.Client.BasicAuthCredential' -ArgumentList $netCred
$winCred = New-Object 'Microsoft.TeamFoundation.Client.WindowsCredential' -ArgumentList $netCred
}
'Credential object' {
if ($Credential -is [Microsoft.TeamFoundation.Client.TfsClientCredentials])
{
return $Credential
}
if($Credential -is [pscredential])
{
$netCred = $Credential.GetNetworkCredential()
}
elseif ($Credential -is [System.Net.NetworkCredential])
{
$netCred = $Credential
}
else
{
throw "Invalid argument Credential. Supply either a PowerShell credential (PSCredential object) or a System.Net.NetworkCredential object."
}
$fedCred = New-Object 'Microsoft.TeamFoundation.Client.BasicAuthCredential' -ArgumentList $netCred
$winCred = New-Object 'Microsoft.TeamFoundation.Client.WindowsCredential' -ArgumentList $netCred
}
'Personal Access Token' {
$netCred = New-Object 'System.Net.NetworkCredential' -ArgumentList 'dummy-pat-user', $PersonalAccessToken
$fedCred = New-Object 'Microsoft.TeamFoundation.Client.BasicAuthCredential' -ArgumentList $netCred
$winCred = New-Object 'Microsoft.TeamFoundation.Client.WindowsCredential' -ArgumentList $netCred
}
'Prompt for credential' {
$fedCred = New-Object 'Microsoft.TeamFoundation.Client.CookieCredential' -ArgumentList $false
$winCred = New-Object 'Microsoft.TeamFoundation.Client.WindowsCredential' -ArgumentList $false
$allowInteractive = $true
}
else {
throw "Invalid parameter set $($PSCmdlet.ParameterSetName)"
}
}
return New-Object 'Microsoft.TeamFoundation.Client.TfsClientCredentials' -ArgumentList $winCred, $fedCred, $allowInteractive
}
}
<#
.SYNOPSIS
Gets information from one or more Git repositories in a team project.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsGitRepository
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])]
Param
(
[Parameter()]
[SupportsWildcards()]
[string]
$Name = '*',
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$id = $tp.Guid
$gitService = $tpc.GetService([type]'Microsoft.TeamFoundation.Git.Client.GitRepositoryService')
return $gitService.QueryRepositories($tp.Name) | ? Name -Like $Name
}
}
<#
.SYNOPSIS
Creates a new Git repository in a team project.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function New-TfsGitRepository
{
Param
(
[Parameter(Mandatory=$true)]
[string]
$Name,
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection,
[Parameter()]
[switch]
$Passthru
)
Begin
{
Add-Type -AssemblyName 'Microsoft.TeamFoundation.Core.WebApi'
Add-Type -AssemblyName 'Microsoft.TeamFoundation.SourceControl.WebApi'
Add-Type -AssemblyName 'Microsoft.TeamFoundation.Common'
}
Process
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$gitClient = Get-TfsHttpClient -Type 'Microsoft.TeamFoundation.SourceControl.WebApi.GitHttpClient'
$tpRef = [Microsoft.TeamFoundation.Core.WebApi.TeamProjectReference] @{Id = $tp.Guid; Name = $tp.Name}
$repoToCreate = [Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository] @{Name = $Name; ProjectReference = $tpRef}
$task = $gitClient.CreateRepositoryAsync($repoToCreate, $tp.Name)
$result = $task.Result
if ($Passthru)
{
return $result
}
}
}
<#
.SYNOPSIS
Deletes one or more Git repositories from a team project.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository
System.String
#>
Function Remove-TfsGitRepository
{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')]
Param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[SupportsWildcards()]
[Alias('Name')]
[object]
$Repository = '*',
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Begin
{
Add-Type -AssemblyName 'Microsoft.TeamFoundation.Core.WebApi'
Add-Type -AssemblyName 'Microsoft.TeamFoundation.SourceControl.WebApi'
}
Process
{
if ($Repository -is [Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])
{
$Project = $Repository.ProjectReference.Name
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$gitClient = Get-TfsHttpClient -Type 'Microsoft.TeamFoundation.SourceControl.WebApi.GitHttpClient'
if ($Repository -is [Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])
{
$reposToDelete = @($Repository)
}
else
{
$reposToDelete = Get-TfsGitRepository -Name $Repository -Project $Project -Collection $Collection
}
foreach($repo in $reposToDelete)
{
if ($PSCmdlet.ShouldProcess($repo.Name, "Delete Git repository from Team Project $($tp.Name)"))
{
$gitClient.DeleteRepositoryAsync($repo.Id).Wait()
}
}
}
}
<#
.SYNOPSIS
Renames a Git repository in a team project.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
.INPUTS
Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository
System.String
#>
Function Rename-TfsGitRepository
{
[CmdletBinding(SupportsShouldProcess=$true)]
[OutputType([Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])]
Param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[object]
$Repository,
[Parameter(Mandatory=$true, Position=1)]
[string]
$NewName,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection,
[Parameter()]
[switch]
$Passthru
)
Begin
{
Add-Type -AssemblyName 'Microsoft.TeamFoundation.Core.WebApi'
Add-Type -AssemblyName 'Microsoft.TeamFoundation.SourceControl.WebApi'
}
Process
{
if ($Repository -is [Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])
{
$Project = $Repository.ProjectReference.Name
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$gitClient = Get-TfsHttpClient -Type 'Microsoft.TeamFoundation.SourceControl.WebApi.GitHttpClient'
if ($Repository -is [Microsoft.TeamFoundation.SourceControl.WebApi.GitRepository])
{
$reposToRename = @($Repository)
}
else
{
$reposToRename = Get-TfsGitRepository -Name $Repository -Project $Project -Collection $Collection
}
foreach($repo in $reposToRename)
{
if ($PSCmdlet.ShouldProcess($repo.Name, "Rename Git repository in Team Project $($tp.Name) to $NewName"))
{
$task = $gitClient.RenameRepositoryAsync($repo, $NewName)
$task.Wait()
if ($Passthru)
{
return $task.Result
}
}
}
}
}
<#
.SYNOPSIS
Exports the contents of one or more Global Lists to XML.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Export-TfsGlobalList
{
[CmdletBinding()]
[OutputType([xml])]
Param
(
[Parameter()]
[SupportsWildcards()]
[string]
$Name = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
$xml = [xml] $store.ExportGlobalLists()
$procInstr = $xml.CreateProcessingInstruction("xml", 'version="1.0"')
[void] $xml.InsertBefore($procInstr, $xml.DocumentElement)
$nodesToRemove = $xml.SelectNodes("//GLOBALLIST") #| ? ([System.Xml.XmlElement]$_).GetAttribute("name") -NotLike $Name
foreach($node in $nodesToRemove)
{
if (([System.Xml.XmlElement]$node).GetAttribute("name") -notlike $Name)
{
[void]$xml.DocumentElement.RemoveChild($node)
}
}
return $xml
}
}
<#
.SYNOPSIS
Gets the contents of one or more Global Lists.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Get-TfsGlobalList
{
[CmdletBinding()]
Param
(
[Parameter()]
[SupportsWildcards()]
[string]
$Name = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
$xml = Export-TfsGlobalList @PSBoundParameters
foreach($listNode in $xml.SelectNodes("//GLOBALLIST"))
{
$list = [PSCustomObject] [ordered] @{
Name = $listNode.GetAttribute("name")
Items = @()
}
foreach($itemNode in $listNode.SelectNodes("LISTITEM"))
{
$list.Items += $itemNode.GetAttribute("value")
}
$list
}
}
}
<#
.SYNOPSIS
Imports one or more Global Lists from XML.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.Xml.XmlDocument
#>
Function Import-TfsGlobalList
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[xml]
$Xml,
[Parameter()]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
[void] $store.ImportGlobalLists($Xml.OuterXml)
}
}
<#
.SYNOPSIS
Creates a new Global List.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String / System.String[]
#>
Function New-TfsGlobalList
{
Param
(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName='Name')]
[string]
$Name,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName='Items')]
[string[]]
$Items,
[Parameter()]
[switch]
$Force,
[Parameter()]
[object]
$Collection
)
Process
{
[xml] $xml = Export-TfsGlobalList -Collection $Collection
# Checks whether the global list already exists
$list = $xml.SelectSingleNode("//GLOBALLIST[@name='$Name']")
if ($list -ne $null)
{
if ($Force.IsPresent)
{
[void] $list.ParentNode.RemoveChild($list)
$overwritten = $true
}
else
{
Throw "Global List $Name already exists. To overwrite an existing list, use the -Force switch."
}
}
# Creates the new list XML element
$list = $xml.CreateElement("GLOBALLIST")
$list.SetAttribute("name", $Name)
# Adds the item elements to the list
foreach($item in $Items)
{
$itemElement = $xml.CreateElement("LISTITEM")
[void] $itemElement.SetAttribute("value", $item)
[void]$list.AppendChild($itemElement)
}
# Appends the new list to the XML obj
[void] $xml.DocumentElement.AppendChild($list)
# Saves the list back to TFS
Import-TfsGlobalList -Xml $xml -Collection $Collection
return Get-TfsGlobalList -Name $Name -Collection $Collection
}
}
<#
.SYNOPSIS
Deletes one or more Global Lists.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function Remove-TfsGlobalList
{
[CmdletBinding(ConfirmImpact="High", SupportsShouldProcess=$true)]
Param
(
[Parameter(ValueFromPipelineByPropertyName='Name')]
[SupportsWildcards()]
[string]
$Name = "*",
[Parameter()]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
$lists = Get-TfsGlobalList -Name $Name -Collection $Collection
$listsToRemove = @()
foreach($list in $lists)
{
if ($PSCmdlet.ShouldProcess($list.Name, "Remove global list"))
{
$listsToRemove += $list
}
}
if ($listsToRemove.Length -eq 0)
{
return
}
$xml = [xml] "<Package />"
foreach($list in $listsToRemove)
{
$elem = $xml.CreateElement("DestroyGlobalList");
$elem.SetAttribute("ListName", "*" + $list.Name);
$elem.SetAttribute("ForceDelete", "true");
[void]$xml.DocumentElement.AppendChild($elem);
}
$returnElem = $null
$store.SendUpdatePackage($xml.DocumentElement, [ref] $returnElem, $false)
}
}
<#
.SYNOPSIS
Changes the name or the contents of a Global List.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function Set-TfsGlobalList
{
Param
(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName='Name')]
[string]
$Name,
[Parameter(ParameterSetName="Edit list items")]
[string[]]
$Add,
[Parameter(ParameterSetName="Edit list items")]
[string[]]
$Remove,
[Parameter(ParameterSetName="Rename list", Mandatory=$true)]
[string]
$NewName,
[Parameter(ParameterSetName="Edit list items")]
[switch]
$Force,
[object]
$Collection
)
Process
{
[xml] $xml = Export-TfsGlobalList -Name $Name -Collection $Collection
# Retrieves the list
$list = $xml.SelectSingleNode("//GLOBALLIST")
$newList = $false
if ($list -eq $null)
{
if (-not $Force.IsPresent)
{
throw "Global list name $Name is invalid or non-existent. Either check the name or use -Force to create a new list."
}
# Creates the new list XML element
$list = $xml.CreateElement("GLOBALLIST")
[void] $list.SetAttribute("name", $Name)
[void] $xml.DocumentElement.AppendChild($list)
$newList = $true
}
if ($PSCmdlet.ParameterSetName -eq "Rename list")
{
$list.SetAttribute("name", $NewName)
Import-TfsGlobalList -Xml $xml -Collection $Collection
Remove-TfsGlobalList -Name $Name -Collection $Collection -Confirm:$false
return Get-TfsGlobalList -Name $NewName -Collection $Collection
}
foreach($item in $Add)
{
if (-not $newList)
{
# Checks if the element exists (prevents duplicates)
$existingItem = $list.SelectSingleNode("LISTITEM[@value='$item']")
if ($existingItem -ne $null) { continue }
}
$itemElement = $xml.CreateElement("LISTITEM")
[void] $itemElement.SetAttribute("value", $item)
[void]$list.AppendChild($itemElement)
}
if (-not $newList)
{
foreach($item in $Remove)
{
$existingItem = $list.SelectSingleNode("LISTITEM[@value='$item']")
if ($existingItem)
{
[void]$list.RemoveChild($existingItem)
}
}
}
# Saves the list back to TFS
Import-TfsGlobalList -Xml $xml -Collection $Collection
return Get-TfsGlobalList -Name $Name -Collection $Collection
}
}
md5: 9A083131F32D9A86F74950ACA4A3F460 | sha1: 675B74917F9860CB9BC90762FA935DFBAA3E327B | sha256: 26BC243D729F3A993650D92D236C5BC7D660ED51DF3167CAF6C525053D3B11DA | sha512: 837E7AC38F3C85DB27C38D131BBBACCC33B34E7076BC27AD0AC0CCFF542950353AF019B14F18BA034635AD92F24B47A572B26D3EFA1C02C393D77CBAB9A871B3
md5: 8D04013C85119CD72E4A4F2E42950DF5 | sha1: 358E458A3F13C0483FD1A606E4C2D33230925632 | sha256: 7FD5C5D5F5872505DCE24F9E3453BEFF214EE16D80A2EA95FEDABBFBE081CC37 | sha512: 31B75477DAB91D68311134CE17DA3ACA6384C5853C10F88EC509DB284F1A1AF962AF6F0C0AAE490EB293D3F53332A8B3128486AE8F3C8ED6ECDF5AA2D0E730B4
md5: A9F71D538D62467E2464152CB7C40979 | sha1: A339187E1F3B5C79CCD91290D18D1404117190B1 | sha256: A8B01CDBDAC57BD10EF205FB9B869F1EFFDC5CE46657022EBC6F5B4BA3F6A8A2 | sha512: 530F623E67BB4EA60C1B55AB47E81449ADC9213FAFC2DFEEB61CBCA0FC258F0DCBD00FBEF19AAEDA0AAA685A4EF1EBED5B2A22701F179CF9BCF118DAE5B2C824
md5: BC5CA7E952350F5CA22F6DC454814F38 | sha1: 7702BF2A7B4FFD0ED77BCACB16D593BCC0EF80C2 | sha256: 9D69766CF30214A83525465228C8B933C3D0D45A54D81433C1E97BB74466DC59 | sha512: AA807B9CFA0CDF3661C03EA736218F5EF7D1F17341D7347F2B4FA2CF5DF70E7CEC96B33DDDD5507E79A91BAAEBE04022E207A05A8B386B1FCFA104A80CAEECE3
md5: 8ABABE0BFAC92A21A295BFDD888F0AE7 | sha1: D99F28BBA4EE36A6CACE95C36E559DA07D7E8E3C | sha256: 7DD91EE375F2DCF588BD9E4DACF5313F637650B956FEFB25FEC440298038F1EB | sha512: 04227EEF032AFF9B001F28ACE6F552033C5A382D8CF010EFA52634C24402001BC35563D098A3007C97E017575125057BE92A3A4063A74202BA03D0FBBDC2BC88
md5: EFC8160FC49CEB3640AAE71FDBADBD6E | sha1: BFE23A1780BC64EC2096A9442FF6B93806CDE71B | sha256: E6CF3B830E6E8BE0BEE53BE3A3DF5D6D8B7D1D827C0E3265FED4CF93AA94C6E2 | sha512: DBAF2EC848AA219D4440DD27B36F113F70DB73E7D4D2ECCFB01A2540EDD28452DB394F9A27BCFA64F17622358EE23C5E225EA96460A28DFC5AC50170F46DFBCA
md5: ADED400E9A07AF2168CB96326E834034 | sha1: 45B843D98677793971AB48E404525613B6C925E7 | sha256: 9BC1963C25918ECC319E2E7CFF82D4F4434E1643A278868E8583C1FC285A97FF | sha512: 3BC5F14D8A52B2AD56E8A348534F1DB8D3673AF248C677B66F794A94137386B7B849DFC13C4D586163BEAA19F8BE72392187F36C1EA5091CCAA0685BC57C4FC6
md5: E6FC376F157138133D8CFC9D99571AEA | sha1: C819607437B5D064246F511D42C7DF5A2CBA560F | sha256: 54BFB663F843E7DCCE0BA18D26E0835074BFC752EFDD54870A972A5887061004 | sha512: 5BD423721C996D7324D0080DFC4958E431251D47CFAE4E7C02236EE4ECAF981ED8E2904073F79BF47675C409623166D1B8531446C9C57BE8635E7467FE995D65
md5: E55818C2B8634467796DB74CD3F4C1E3 | sha1: D043CA80A509721F0D49E4941091828BC1B9DA98 | sha256: 55A2C808100DBFEB7311806DCB6B25EB16136AD8E0C80B86C2E2AC05A634100B | sha512: B80C0967D16CD748FEAAD36DD6EC0568EE7A03A09A8CBEDAE4255B9FFD61F80519DB8BD7F6C6D09D0CBAD434286C0BEAE7C6CADD42F5CE18BE839801ECA06CC9
md5: E2B7395A40D4F1B3D851F375F9D48A93 | sha1: 793071301451C61BA2DB863DA46006C358B43468 | sha256: 5019731C050F0974D72C8B35458A6BFAEC8CE6192F9AF9536477457194D25727 | sha512: A9781BD09A491721F29874F2CF7411693A71AA8BB86BAFD41B444372A1FC6341800E1F3A99150E4C90A90B9701720EF53FF8F4ECFF9E1FCA265232B07AF19DE5
md5: 3925BF5D21F35228E402BF7BFA9667F4 | sha1: 76ECB97421AC9E704059A3DEBBD63A042A5B6C7C | sha256: EDFB834E3AC9FEE222C012C32AF84BDB07B1AEE081FD85443773FFBF8A7AA780 | sha512: EDE6B1B08F05590121809F43577EAFDE4789C5D6AACDA9E5D022B76A7A006953917EC006ACFCA0D4F2301A895C67F3443AF1BFF2CEBB02AB9F0B60D7A63197A0
md5: 51F762691CD5EEC93860920C45ECA1E4 | sha1: 87E0CEFC1760DF947FAB07AF0485AD6BB3BEC6F3 | sha256: 78E7FFA1A92A1F4A07943448F3EE78913AAD38716BE42CEFE0F9E64F34A4359E | sha512: 9F49A25105C765BBE0D04F8E41A87342DAEC047F182EA4C85691BEF1138CF8730E09863104F0110D3873F159E57538F36E67CF1DF33AA7179133CEED02503144
md5: 1883EB1F17EC1FE19ABE19CDE72205AE | sha1: D602F04C364126AC8C670D44243C755AAEE06051 | sha256: 016E83064E188BD69F8072E1E042629143D98F0486F2BB1F687498071DA986F7 | sha512: 051261150421513F6B247F76821B207E73BE0FC4CA6A03101450A13305BC687163345EC21A7CA05D5ACB2F30DFF01A8F8BCD41928575A40852DEE3E63DD1AAD1
md5: 5099B579010540D661DA81C71F8ADC1A | sha1: 353DFF2A03A1ECB4D7C73F81CF5FA06F3C005E5E | sha256: 22E0B259F5A6D19327CF2D854A23E617890ADECCDB8914C8BA9235E3BD4B73AE | sha512: CF085120D2A8DC2E46AE82CC2949A05C11772B21EB3705D0FA49F7438750C080BD1AF9748BCF4EF3A292BB25A6E6796D2DE4CB40A7019C04CEB9B1E1211D52D5
md5: 0A883A318A936B72C3F6B58AEED4FE23 | sha1: 848FD4DBEEEAFAE318967ADA8CA96C58AF66E7B7 | sha256: 39E4394864C56B61EFDCD25DF55FBC55553847675B4B6F233F1559444C6FDDA2 | sha512: F0C16351D881E170F3B4C8054797595A5020EC419072D3051B0FB166E3F7778DD8BA797FC0D721239B482D385A40029576DD95141D0FF37355F6B201B424EB58
md5: 007D27EDD4245657656ED0108FCD6117 | sha1: 602F4D39D07960F742587C749BDC0B4440E37D62 | sha256: 5B9D4281748AD1C3B0EE5982E4E01335BA7149E1D1DB0344C8EB308FBE34D2BF | sha512: 691E5E5BA8BABAA6A419604A4B6AD77E7D5E605D6C6BD67421DF1882D072F6704306A7C9F51830CE93B9942DA48276934ED686AAE5628416F4CF987B87F3CC2D
md5: EE40B7745563E73ABE247633D1B5D675 | sha1: E2A7B33658212F60FA4C2C63017D84559F77AAE8 | sha256: BCE9E0DF26D730DD87896EA5DE064C0451AD15AA221ADBE7F28BC5DF093F1A42 | sha512: CD06B16771E56A3C2DBC68DC94E688D64E69A43DFABA3F30A9E6D97FAA44755120A899A2517DA15C5F42AC6755F24B693AC19C9984ED07AC27C9D4814D54988C
md5: 1C7B968FDCAB3B8820CB25BA9F3B0CCF | sha1: C35C460850F039A19275A8A882FB17B4F786E09B | sha256: E998158C98C8A65EBB72576CF72F4CCE2AB3E7F57D083486DDC69E113EBD2536 | sha512: 1490BFE353800630F38F667B72B07A7D365AEE0F51E44C812AA6D906CB327019477B5471C2F58BD1BC1B7F052F0C06EE38E13BA111878D3EA8C6A4632179DB97
md5: 979B5429205C3766F7E270A68818DCE5 | sha1: 5F97A90BF2B7ECFF33E8E6DE7E952D31D0EE7CFA | sha256: 2BAB0FB7D4922781C764961D38A364D2E916236F54DFD1F8714B86498D4C4A89 | sha512: 20777EF5B7444DC81485DE680AFB5CC96CBFCD694FA4D8B4239AA67C053625E9ECCBDFECC15A480BAE8C3E1C2E6D4231BBD1D15C96BF3D8B40A5DC0EE656DCC1
md5: 35D541FDB0A6B14CC493C71B727701F0 | sha1: 84143EDFA00BC5B97FAC7308DD40956130124780 | sha256: 1A22D862A846596F7C0633FE56405B854677066FC46C9D64EDDFFC14792EE6B0 | sha512: E1E3A595BF43FFF14EE8E223EED40F35CBADA8A7DF18E493C792E2AE87A7DF27B1EEB080E500FD3B3D537F2340C02799F2D00167778EBDB142C63E2D27B9B7C7
md5: FE924FA51ED6C074A8680E48FF04668B | sha1: 6A052CCB131061E6F9CBA6215DF41E94D2C80E9F | sha256: 73EEA8AC56F319D5766B757D09353F7D0E655616F73496CC163EDF9D5319C567 | sha512: 481EF1360608524BA5B3F3E8DD304C71D71AEDDAE80D80F480B4A99FE6E73D2175CAE402408F25FF8F002BCBB6C2856B5C8E6B036FBA3116343039702DC8DA17
md5: A69BF20D989A7D0AD1781269AE47FA81 | sha1: EFF8A572FD9F042F631D6B546FD095CE09BA14B4 | sha256: 4EA4A391F1196C000A8069524873AE1275279722371D3E97FB87811B525A2A26 | sha512: A773476B1C29DE25DF6962BBC8818CA614D4546ED1E3AD58495EBA5EA742A0D9445FBA889B112DE4EE159797A52905DCD15460B79ACA2485389CF73E2C92DA73
md5: AD077BB0F848A098D08BA44F163F98AD | sha1: 0E25BDA23B6486FA294E387FB0AD05D16B2D7510 | sha256: 271B5FD9AF4E50F29AE87E1BE24A25B3848DB7A6B03CF286C70FB3324E55872E | sha512: A7B95A61AF89C463724F25A35602272918EC9E6E48A70C78DB27AB541E145423E616C46E14976E81E84EFA3C8B01FE0453C580A7EED642EC058614F15A404D81
md5: B9BAFE7ED4F2D6A380DE093ABA850BDF | sha1: 602C9C740ABCC4AAABE2C03F5445CE79951DBEEB | sha256: 4AEDD0EAA0B6C5DE814B01D83F6A1CE48EB639EE91CED632F06BFA65665F50FF | sha512: CFF11B330EA97BD28C98E66CEC37968BCC098DF26CBDB9E5A6E6511181BD01DEC9F89D533AAA248D45E6FF8BEA954B9D5D7D7BE5688A507B7267416B12E33B7B
md5: B3D08EAC795369E764E9E943D7C63B28 | sha1: D62569A546BAAEBFE15E67B7AE737DF50FE38435 | sha256: 46A71879E8B6E07AA3BED51A568BC45DDCC0489C17A08FA8E9DC4F6EB26F8936 | sha512: 470DCE66A88E071A45C58A28CEA66630F4F7934CF0A969120B26EB164E6166A8FEC0F2C77C44F54AD63F4D2DE6FA3BC240AE7F9BC2D87740B6C20A856B3E4D31
md5: 06343C1D5B24D3A0A19A6E9DC556EF32 | sha1: 6EF67FE03123F5162B599DB30C2DF1389D9B912D | sha256: E22FE77E9A9265002ECD1BA0049C8BEBE82CE9D1BA380C2C26D8F0C90F669B6F | sha512: B670F04DC0E3FE866CA93BC44E05F16957CB149EFBB73BE65162D6BC0197D5A24FEDE012E7EA44E22FA86A147758DE12F372966B00B54938707EC13210555DC9
md5: 279DBA1F536F06CF54DEA3472E97AD02 | sha1: A976C3B88ADBF8A4350F1DE8C616776719285D66 | sha256: 62ACC521B9406B7392BB63ADE9FDA3A4F4798F82DD140528124CD7F0A9E3DE46 | sha512: 31F3A21F984A08B21DBC4E92DB4799C129099EB793A53112375C5DE2B7C6B2698D298AE899CA9752C3BB9289E52173AE86F7A2F57603E6BEB028AB0912AF52B0
md5: 59188B1E92315693B04C91692D1D3EEA | sha1: 02CF25A1BA27CBBE717622D4A7AB45EF4F69F09B | sha256: 48F6478543A99EE29662C9E41166CC0B5B74209E1BA0E0ECF84D54D08A3D25DB | sha512: A2D76A1FC75CE5140D9548A8C91BDB5F2A41DE0BDFE47116D3E725880950E4C7899EB3CFEE32AF35BBA29BA04D505ACB9A049F467895232627E6B89AC3C66EB8
md5: D48A25C86C036BD3A95B5ACB9FE7F9E5 | sha1: C2F82A0A88101BCA821E00398F5D8BB4C0A7AD9E | sha256: CE100108BE01526CFA3D4121E34A730E390677BC7F23F891C11BD474BBD364D4 | sha512: D7AAD653507E98041F755F0E988BEA556F7D3B5B4269B5F61AB9D7D938372BFBD43598E646ADF0F03957033DF2A33DBBF819DC33A4F87CC9EAE06ACE54F489C0
md5: 092D342AA72777158B4B8A6212E8F039 | sha1: 301E960F03026D025FF83ADB9C44F3C55AADF9F1 | sha256: 7476F7BB89EC1D844913140B7F1F139034E26B09970E41FA7406EB7CC97BBA63 | sha512: AFB8CC5675C5B4F63FF455A2CDF20C40A5932091F3D7CB05449B9E16E05BF90D55088D912E533E9A5C2C9AC34D5A227E693F4815D88FCFDF4FE55C2545991B5B
md5: C12A9100830A9611E276D4772BAB3443 | sha1: AD3C0C8040A5C13C85061C6ED7A1BFBE0033AA1A | sha256: 88B7DF735EE01FFB6A71C10F931AC990C8D54B2F93ACA61BC9B798B0F6018110 | sha512: 3CBFE19843A19A0A0FB4C17ACC48845585C74F9DDB0E5D5BA247C7232FDC9F7245675CE6233D4FDC776AC52C4AAB1CEECC1545AA3FCE653D4B637C9364BC3DD6
md5: 84864ADD5E2B2FEA717E19C9A23AE64B | sha1: 1A4E362230AAD8E8C2814AA8B9E131CE772B3EE0 | sha256: 3E3FE48F499D2D45C7764922EEF95D3B219A0DD2DF18B53A56BC728A49D06F79 | sha512: F0EFB9B4BA334B958FCF89C699D0D35CC54C6CC2428F2D721F6EC1D35D4D8518BFB99C6367BE2D947237ED66F221FB1523C28554C31F638C3DE9EB8E9ACDC2F4
md5: 11A31DC9FFC38B654DB3AAB57FD53A60 | sha1: 613D4FE6C16F8D524E9310918D65C8A1F1FC611E | sha256: 83005F91E6D3C8C37D395F7CAA46E650050F502D13FC9FC8787264E72A474664 | sha512: FC160F14B8FC2D162FC0FFB03F7DC3006C814BD3932A2746B3329DDE2CD3B284D84CA702D9A8CE6D6881FDCA7232EE38222FA2B0CEC6D72849720DABDA83FED0
md5: FF2AFE3EBA97BB7953A7E0F0B2D4A8FD | sha1: B72B4053FEA687C67F5E22D4E52E6B4246CA8892 | sha256: 70A4AF6673F0D986977D8681DF1A46245083050595F61F9F4342B2E10F7253A6 | sha512: FB4825EDCA58C065557C7937BD0C5A23A5A1B21D8E27EF7F5649991473ED1B583DE58AA751BE549DA711291B99526525CB7125577ED03CCD267D046E2F86CCA3
md5: 3D4C01F6000211036D8DAAB2C24324D0 | sha1: 4FC4C6AD2C5AA24F98D8B95DD82279655263FE87 | sha256: C5CA0E0A80C4390B04055AC108B7DFA44724BEC00D8424C2D3F02BE31E55ADC0 | sha512: EEA8F9567ADEA8F8CE6FA1B8FF6AFCE680A1AA8F55DD64FF91FBB59E0A44E14CA51951EC6F0D240A2FD345323DACD9AA62657C7159D71F0868FA3000C8CBF800
md5: 59B4D25175D099C0578667431EC1ED03 | sha1: 2C5C56216158368E7A19217E07E734C19BFBC7A4 | sha256: F6EBFD09E3CE8DA2C9B38F9A12C7E7A17BDE467DAB3482EBCCB396ABA23584D6 | sha512: 9BA20067CCDD167A0266392255C366E19FFF4F53656115A726CF2488CA2C5C52DBBF17B9DD91BD83FB23F8D3212745F6CD5E4174267CC7F41DACB6F2352A4C9F
md5: DF4D47184A2B7BA1C88D55C7A5EF1BB2 | sha1: 1FE04EFE11AF9AB536B576E029902F499082F2C2 | sha256: 56694941E5C1B21695B7416BEE94C0F82F0962E587D112A397A305E58B0D0ECE | sha512: A00DDC9CC6F95A12B45AE3E32685593BB35929F533BA15182D6D07355CACB291AFBBBFFAD42713BC9EEE7F00E7A0DDB0AF85C5295E0F6897502EA438E69A5D33
md5: EA1F15C787352C9E3CEAF7330E55A30F | sha1: D65D9EC7DBBF419214101589587147D69A9283D6 | sha256: 45CEF3B7030F6A081E5161595C63CBEF006F38E7C9ABF652A8F2AF0EEA90F8AA | sha512: 1B267AC38D642A14440319494EDE10113803D6FAFDFA6FB43B9E9DAADEFC0040B9E6AA5592A29D084DBE4A5762748CE02E725AC20AC2CB67807E72DF206969CF
md5: BB746BD32ED2EFB212951067094AC5BD | sha1: FFC39F6D81AEC57F502B0562CDD452D87241F11C | sha256: 28CF4BF8DAFA2A8AE7050BBD81B06A1CDAC78AB4299F4D80F05645CF1A92BA9E | sha512: 6A69403078C12327F739F387BA2ACE62B083B07AF9AECE7121FB3E49580B9DBCDFA7E2AB02CCA7C4ACC75727D0374485CA7D61EE7CA40CDCC63F70474526FCC8
md5: 5BD702AE05B4BFE51A54C741465DBE47 | sha1: F28EE510FDF5F7B6DE5174289B87D8539B414E84 | sha256: 0CA3EB35A8535E8B1D782872DBF9F78569AF59EB9CAEE4F7BFBAC773B7FB2DFF | sha512: F1C6D3AE681B927D1D0B05E99E1646EC3C76CFD44DE5BFA74A7160927142996C058A1931D78EB0A983B4BB17F407C33B96C6623AAC1E17F671BB23A857B18426
md5: E08FBA9900605E17DFAABD423EA73B80 | sha1: 371927246FE8E2AC366137E3B29117D53E1F7DB3 | sha256: 15DD683880F5FB4F45AC8F4EE767217D5932368742EE98447823FC8DFFEEC8D7 | sha512: DBDCE1030AAE3A3E76A01ECD679308EF3A4C45F2E9D31A69F220D68C00D4B66AE2597099BA39218368EC154F6859FE6073F8B88CB21BE09E4C9AEF533F2F688A
md5: 0DA345169D0BE68EBE106136D376F947 | sha1: BC80B181C2C7B62FD7A6E0E8500EDC7A0DB05CA2 | sha256: 818A24D2CB7EA005AB1BD326FC944BF54611382555B0C75EC989F57F8AE49371 | sha512: 1C1D0E37F8E8E4A3A1D6C1C6406CFD123A2BF636E0315A80BF9BBA30AFB0BA832EE1C84494F96B97C718152930DD1D58EBCFB2E48B571FA55E5550A4608886E8
md5: 0AF0F5E04494049D9070B1E659D82BB5 | sha1: 41998E2C601BEFA8BE51DE3605E384DE9ABFAFF8 | sha256: 7380B517D616A8DF3C3E38AA0A2732220FC14BA2227994AE37865ECA258F05F1 | sha512: 86C34C92292E91AC1FD0C42A75EF5759D6992F431E33FF72ECD2E525A4BAED29C1F65F708D0E25C7B47AA0AF191E203EE28C94994F3A6A8F1A9111ED1E7A7BF8
md5: 30E5AFBC97DB52904A0BE1E3203461DF | sha1: D5B1E42FA2AEB2E35D5A3D5CA57CBFDB38FC604C | sha256: D6F323DED8C3E141CC234BF2B00A70FAAF9FE4908DC0A543767D2926B7E3FDB0 | sha512: FD3FC3B07BF6E90E7ACFB92BF4AEB7A37F611C3CCA439CC4BFEA99CBD6B778D44F175F1FDDCFD53E404750C9EBE8067C0A4FAC6316E479B1AEB3CAD2F7A8CA3E
md5: 551AAB3A4E29BD1E9FC022FD2A80C258 | sha1: 771845C3BFCE7FCCB760BE2836062A5E9F3922A1 | sha256: E18F97AB7A54D0FA99D529483919808ABD531DB281E5EDCF69701B6BEDCF0B17 | sha512: 873C8B9E6BE4BCA48C51E11FCBD7BE2DE701B4D0D6E69BF91D29A3883FB1C7BE5BDEABF04ADC7017FCEBE2CD1EDBAB6441FEE9B66EA649792B295367F09CAC49
md5: B5342325CF3993565C1DBFE030E6FC43 | sha1: 9F4423425AE0B72C2A6280D8E34CB6520D9DD90A | sha256: 820BB4AE31FD1B7E2C9A8B6D9CBE304497B6360367E956359A7F42593121C696 | sha512: EEC22B5400594F14F194E32D89DC1ABF1C86357C9F2A3A4C40E5D49D6D58F02DB672C38A31350EC188D46C6CBF3E10B492C03B141837AE0935059BC1544C199A
md5: 5B9C088F62B68A97D889406EDD6B0941 | sha1: 95A193F006078D60494E3B3AE2ABB215039C5FBA | sha256: 1090BCA31222EB0E1CF11D61A6F2BC062FF61CDB1C79FD48A6B53AF04720ADF4 | sha512: 9DCCD3FF2AD35D8EF70CDC95F5D46A571EC8C47F2B100C38F1D2C9C663055A91679134802FB3857EACEE685FD8A52BD77E03E6570F4F5FEB2012B2ADE7CFB9D1
md5: 74C4B94F7ED7C0F54FD2B2B3D40DA903 | sha1: 1C7C756EE59820A77287D4086EDDD3784DBEAA44 | sha256: 449B4231DCCBE8D204F587A5192F783761CF7F045F543314E56B40B7CEFE576C | sha512: E4A00B217CA178CC6C801C315D4ABC836F5669EC03BC9525D821526F2B06BE3C8FCFED67030FBCFDCD3CCE2D91B695AF0D3B34964B71A316810E9FB8D2996E7B
md5: 752421D8A0AE6BD396FC94FBB1C504D5 | sha1: 81F5FDF31A14D1CE68D0C8101873BB55EEDF6BEE | sha256: 561CC90167209DE0B8208BD2994A094D95179B6E0A028E2C416653FBBEDB6442 | sha512: 43436424042716889C96C098C42340F2B277211F41D9CA41493AE17642415096EEE18A7B1435BE19FC5DCFE26C70D48E3616CDD4B65EDDC97CFD76D7FCD46D70
md5: 85F8BAD71F7448D0251ECD79F7D2F30E | sha1: 106612AD0CDA075E0D858AAE733971B50282171E | sha256: 300EF524F8A938CD1F3625F0BADC6A7F594F159F3A2C0B8D4D784B7B09BA2547 | sha512: 3694C8A9FCDBB9EE5F736B9A675DAB79CA631C3C4375C74C7679F59AA0A3B5F4447307212D53E52E6C2359EFC462A51B96D6128525B3804B58A442647D41BC64
md5: 4BA9ADF1602BEE7004A6EE0ED84DE446 | sha1: 457E5939DFA2CE6E475BF2D8AF75D824FF4D10E6 | sha256: 94AEC4FD3D338231A146A456A94EFFF99B2A34B9E30D51ECDE1997000D8D4C08 | sha512: 5AC79394F44E16F72FA2F640995E243987896EE5124B1222228C58D21036485F814E1C0895CEF1616765040415EAD245EE53B9D0D0940F2B7C575CE14AF6D594
md5: 0FC2047E361B79AC15755B1ED400F819 | sha1: 638F36DCC3A8131B8BEBDFB3A0930A764AA9984B | sha256: 76EA4B2D47BB238C1F2AC0C62F1BE4D34BC71397662E3760EA0C684EC4A429C0 | sha512: 3BE94E64E45B7369C37DE381DEBC6BF19D216E470EC4C01778FA1B8B7AE99E5CD230FE896BDBDC693CF889A744FA1C0234E86052D2FE92E29C73F47D6D8EF57D
md5: A07D580BD6100185013D089A3B03D9BB | sha1: 1D35B5E478E469CBFB9FAAC9B94CB704BD485073 | sha256: 927E596A90D0020DC9B2F1AFE806DCBBB6F1C0088A5B368BA3BC9E40510F7184 | sha512: 12665EE71DE617ABDC96FBB20E626F29F81BD4D447C697C1A144E6BB8D78DAD249AF7B5798AD41CB7558744519A39D5094B33E319C21E75E86404003487B8C27
md5: 1BC23C66FC9AF1E7F06A67C9DC94ED2F | sha1: AC22CA74A66FE34B645CDAAB6088FF9CAFB19EEE | sha256: CEC22B4F62A4975DFB724B6564C12DC03717C79005AAAF6128269CB70B5356B6 | sha512: 33135CAAF1053A2633A520940888FDBC02754CAF3A4A9A9B86AE98B9E3F4816430DC75CF629D40D92CEB1ADBCD121ECED23AD0FCE341654CF708B3FDE0B4D6B7
md5: 33AA92DA1D25321E749B094D795206FB | sha1: E5E377FB566D4A10B2B42AB45505A0E03FDC0F51 | sha256: 9BC022DAE6B25E50F317860861953D24C12CF76FEE8B2B10F52BA352DCE90083 | sha512: 29B74AD584435F85DAAAAB9EB711D5E70E7BBCEBA65215DF51652F72B9B1B5E9715433C95EA27852C793A8AA76C1105CA12D308ED141B60AA037516A7D3D0DD9
md5: 826CDF5C864DBA3FAC283E694B5D300E | sha1: 452039516E53E284D9DB5112CD1D5D50A954C1E2 | sha256: 53E97936AF2E5FB19E4D9159C13B83B49CF76BCF7D251930E0E11A66332BBB5A | sha512: 31DCA2D1957A8404414FCB8D4A63820C8B2CA1A556C4DB3D6644EB71D917B0278C2753B2B0A6E51B496A722FA8047F783A7AB88371E34CEC97F4FC08F5462079
md5: CA15AAC54D77619592D5DC84807A656D | sha1: C1C7140A46ABC84652577CA2678D636E194B0CEF | sha256: 3AAC33EE0485D9A9C9BF132F885ECF4C055CCE16D4AE4ED1B544F4ACE9FB16E2 | sha512: ED404087EF2052881C34E1E39297C17099E4506AD43D2DDEE1588D607BF0BA1A92E6A3037C7C373CF54F8AE11B7DBA0D0B3C43AB3F99C63C313BDE9E78F6D1E6
md5: 29E3DA44FBB31CB42FDECC858D8DD135 | sha1: FF2B1B7F1EFF0E374387BBCED855624DFD188D44 | sha256: 24DA52CDA5C95EE94A68EFC99858CB51D6C4FAF45FBF710F04D2738A99EC3FA0 | sha512: 706C119C7215FF790DCF7BD7A50F1B23F0F65A0543E440DBC7B52B97415CA73C9759FAB039B3246B26909CFE3409616331B7F8116A6370C8D387CCC93D667106
md5: 7CE79C8AC5C03D0CF6022987990995E5 | sha1: C53648AB025F66A22B87CBC0AF2F648639E32731 | sha256: 524AA03E14A3EA9EB81CE60A2F5FDF42F5A89372842F4DF030383E3DF290A903 | sha512: 5C245B99811FA8002D10E477D2A33CA89F768CC96B918F242225C990F98766B5287B6D90B3B52D1737E6FFDFE0ACA4FDD4BEB152E7739861E86FB4FC0687489C
md5: E2B05593588008876B1F30C4217D71BC | sha1: 50F8D91BF74DA08588E94927054673DDB92C42E7 | sha256: 0E3A82C09873F5C594E4994B5D35201A241462E11ADFF5106E2A5046A28AB797 | sha512: 69B82CB6879E76C2DDF77C813D83F0492AE019EAF0C60B36F1CC88289A7DBEAC0120D83EA7C05CE7C028A453AF918BB83A9EA613E0EC902EC0E3AE020B597C2E
md5: D93A9F9880FA5DA2BC893568B853FDFB | sha1: 1610081CB5EE7065A7AD398122F713FECE92238C | sha256: CE6C6A3D98E7031C902DED034DEF7467143F0E50DF8811F7812E1D0D4EB072DC | sha512: 01BED3B2F4E8A37CA99EE4C4DDED743087AECF1F64952D32D2C1AB0F40B00EAF0A29F1E84C18562E6D1469CEDBCBAF28AD0FF4C47A629CF5BDF3BDDBB8729936
md5: A73B83D7E6F1F1CC25016C5104FE321E | sha1: 634C12F169B3E13140F19B6F7F01E3725A2DC4D6 | sha256: CD113A5C75CBAF9E565C9BC7BCBE09156B82D81D7C73ECE0351472F60F0C8913 | sha512: 17AC97400F167BD344C00493036F431F11289C7F276CB96DBACD23904DCA8C8969EE6AC22B6407661E17B16F31B82BAA89956CF2DB1711652B7328A7322EAAC4
md5: A4B4BD54ED5690E50CB51DB9BFE6EAC0 | sha1: CC2FA76EA2C2BEF2C9A810E17F3B2056D5CFA06F | sha256: 1666E476E6532B3114F0A1B8CD3BA433052F04229AFEF040D79AB8156F1CEEE2 | sha512: 1C821AB1EF444B447D0FD01783B61EBCDA789A9E2CB11C5668B6BA2BF36A3C9F41FAD4EF2C6C94DC56B4F56FD4E17D04A52B6E2F5FB9C70B7608242186C6513A
#
# _InvokeGenericMethod.ps1
#
function Invoke-GenericMethod
{
<#
.Synopsis
Invokes Generic methods on .NET Framework types
.DESCRIPTION
Allows the caller to invoke a Generic method on a .NET object or class with a single function call. Invoke-GenericMethod handles identifying the proper method overload, parameters with default values, and to some extent, the same type conversion behavior you expect when calling a normal .NET Framework method from PowerShell.
.PARAMETER InputObject
The object on which to invoke an instance generic method.
.PARAMETER Type
The .NET class on which to invoke a static generic method.
.PARAMETER MethodName
The name of the generic method to be invoked.
.PARAMETER GenericType
One or more types which are specified when calling the generic method. For example, if a method's signature is "string MethodName<T>();", and you want T to be a String, then you would pass "string" or ([string]) to the Type parameter of Invoke-GenericMethod.
.PARAMETER ArgumentList
The arguments to be passed on to the generic method when it is invoked. The order of the arguments must match that of the .NET method's signature; named parameters are not currently supported.
.EXAMPLE
Invoke-GenericMethod -InputObject $someObject -MethodName SomeMethodName -GenericType string -ArgumentList $arg1,$arg2,$arg3
Invokes a generic method on an object. The signature of this method would be something like this (containing 3 arguments and a single Generic type argument): object SomeMethodName<T>(object arg1, object arg2, object arg3);
.EXAMPLE
$someObject | Invoke-GenericMethod -MethodName SomeMethodName -GenericType string -ArgumentList $arg1,$arg2,$arg3
Same as example 1, except $someObject is passed to the function via the pipeline.
.EXAMPLE
Invoke-GenericMethod -Type SomeClass -MethodName SomeMethodName -GenericType string,int -ArgumentList $arg1,$arg2,$arg3
Invokes a static generic method on a class. The signature of this method would be something like this (containing 3 arguments and two Generic type arguments): static object SomeMethodName<T1,T2> (object arg1, object arg2, object arg3);
.INPUTS
System.Object
.OUTPUTS
System.Object
.NOTES
Known issues:
Ref / Out parameters and [PSReference] objects are currently not working properly, and I don't think there's a way to fix that from within PowerShell. I'll have to expand on the
PSGenericTypes.MethodInvoker.InvokeMethod() C# code to account for that.
#>
[CmdletBinding(DefaultParameterSetName = 'Instance')]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Instance')]
$InputObject,
[Parameter(Mandatory = $true, ParameterSetName = 'Static')]
[Type]
$Type,
[Parameter(Mandatory = $true)]
[string]
$MethodName,
[Parameter(Mandatory = $true)]
[Type[]]
$GenericType,
[Object[]]
$ArgumentList
)
process
{
switch ($PSCmdlet.ParameterSetName)
{
'Instance'
{
$_type = $InputObject.GetType()
$object = $InputObject
$flags = [System.Reflection.BindingFlags] 'Instance, Public'
}
'Static'
{
$_type = $Type
$object = $null
$flags = [System.Reflection.BindingFlags] 'Static, Public'
}
}
if ($null -ne $ArgumentList)
{
$argList = $ArgumentList.Clone()
}
else
{
$argList = @()
}
$params = @{
Type = $_type
BindingFlags = $flags
MethodName = $MethodName
GenericType = $GenericType
ArgumentList = [ref]$argList
}
$method = Get-GenericMethod @params
if ($null -eq $method)
{
Write-Error "No matching method was found"
return
}
# I'm not sure why, but PowerShell appears to be passing instances of PSObject when $argList contains generic types. Instead of calling
# $method.Invoke here from PowerShell, I had to write the PSGenericMethods.MethodInvoker.InvokeMethod helper code in C# to enumerate the
# argument list and replace any instances of PSObject with their BaseObject before calling $method.Invoke().
return [PSGenericMethods.MethodInvoker]::InvokeMethod($method, $object, $argList)
} # process
} # function Invoke-GenericMethod
function Get-GenericMethod
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Type]
$Type,
[Parameter(Mandatory = $true)]
[string]
$MethodName,
[Parameter(Mandatory = $true)]
[Type[]]
$GenericType,
[ref]
$ArgumentList,
[System.Reflection.BindingFlags]
$BindingFlags = [System.Reflection.BindingFlags]::Default,
[switch]
$WithCoercion
)
if ($null -eq $ArgumentList.Value)
{
$originalArgList = @()
}
else
{
$originalArgList = @($ArgumentList.Value)
}
foreach ($method in $Type.GetMethods($BindingFlags))
{
$argList = $originalArgList.Clone()
if (-not $method.IsGenericMethod -or $method.Name -ne $MethodName) { continue }
if ($GenericType.Count -ne $method.GetGenericArguments().Count) { continue }
if (Test-GenericMethodParameters -MethodInfo $method -ArgumentList ([ref]$argList) -GenericType $GenericType -WithCoercion:$WithCoercion)
{
$ArgumentList.Value = $argList
return $method.MakeGenericMethod($GenericType)
}
}
if (-not $WithCoercion)
{
$null = $PSBoundParameters.Remove('WithCoercion')
return Get-GenericMethod @PSBoundParameters -WithCoercion
}
} # function Get-GenericMethod
function Test-GenericMethodParameters
{
[CmdletBinding()]
param (
[System.Reflection.MethodInfo] $MethodInfo,
[ref]
$ArgumentList,
[Parameter(Mandatory = $true)]
[Type[]]
$GenericType,
[switch]
$WithCoercion
)
if ($null -eq $ArgumentList.Value)
{
$argList = @()
}
else
{
$argList = @($ArgumentList.Value)
}
$parameterList = $MethodInfo.GetParameters()
$arrayType = $null
$hasParamsArray = HasParamsArray -ParameterList $parameterList
if ($parameterList.Count -lt $argList.Count -and -not $hasParamsArray)
{
return $false
}
$methodGenericType = $MethodInfo.GetGenericArguments()
for ($i = 0; $i -lt $argList.Count; $i++)
{
$params = @{
ArgumentList = $argList
ParameterList = $ParameterList
WithCoercion = $WithCoercion
RuntimeGenericType = $GenericType
MethodGenericType = $methodGenericType
Index = [ref]$i
ArrayType = [ref]$arrayType
}
$isOk = TryMatchParameter @params
if (-not $isOk) { return $false }
}
$defaults = New-Object System.Collections.ArrayList
for ($i = $argList.Count; $i -lt $parameterList.Count; $i++)
{
if (-not $parameterList[$i].HasDefaultValue) { return $false }
$null = $defaults.Add($parameterList[$i].DefaultValue)
}
# When calling a method with a params array using MethodInfo, you have to pass in the array; the
# params argument approach doesn't work.
if ($hasParamsArray)
{
$firstArrayIndex = $parameterList.Count - 1
$lastArrayIndex = $argList.Count - 1
$newArgList = $argList[0..$firstArrayIndex]
$newArgList[$firstArrayIndex] = $argList[$firstArrayIndex..$lastArrayIndex] -as $arrayType
$argList = $newArgList
}
$ArgumentList.Value = $argList + $defaults.ToArray()
return $true
} # function Test-GenericMethodParameters
function TryMatchParameter
{
param (
[System.Reflection.ParameterInfo[]]
$ParameterList,
[object[]]
$ArgumentList,
[Type[]]
$MethodGenericType,
[Type[]]
$RuntimeGenericType,
[switch]
$WithCoercion,
[ref] $Index,
[ref] $ArrayType
)
$params = @{
ParameterType = $ParameterList[$Index.Value].ParameterType
RuntimeType = $RuntimeGenericType
GenericType = $MethodGenericType
}
$runtimeType = Resolve-RuntimeType @params
if ($null -eq $runtimeType)
{
throw "Could not determine runtime type of parameter '$($ParameterList[$Index.Value].Name)'"
}
$isParamsArray = IsParamsArray -ParameterInfo $ParameterList[$Index.Value]
if ($isParamsArray)
{
$ArrayType.Value = $runtimeType
$runtimeType = $runtimeType.GetElementType()
}
do
{
$isOk = TryMatchArgument @PSBoundParameters -RuntimeType $runtimeType
if (-not $isOk) { return $false }
if ($isParamsArray) { $Index.Value++ }
}
while ($isParamsArray -and $Index.Value -lt $ArgumentList.Count)
return $true
}
function TryMatchArgument
{
param (
[System.Reflection.ParameterInfo[]]
$ParameterList,
[object[]]
$ArgumentList,
[Type[]]
$MethodGenericType,
[Type[]]
$RuntimeGenericType,
[switch]
$WithCoercion,
[ref] $Index,
[ref] $ArrayType,
[Type] $RuntimeType
)
$argValue = $ArgumentList[$Index.Value]
$argType = Get-Type $argValue
$isByRef = $RuntimeType.IsByRef
if ($isByRef)
{
if ($ArgumentList[$Index.Value] -isnot [ref]) { return $false }
$RuntimeType = $RuntimeType.GetElementType()
$argValue = $argValue.Value
$argType = Get-Type $argValue
}
$isNullNullable = $false
while ($RuntimeType.FullName -like 'System.Nullable``1*')
{
if ($null -eq $argValue)
{
$isNullNullable = $true
break
}
$RuntimeType = $RuntimeType.GetGenericArguments()[0]
}
if ($isNullNullable) { continue }
if ($null -eq $argValue)
{
return -not $RuntimeType.IsValueType
}
else
{
if ($argType -ne $RuntimeType)
{
$argValue = $argValue -as $RuntimeType
if (-not $WithCoercion -or $null -eq $argValue) { return $false }
}
if ($isByRef)
{
$ArgumentList[$Index.Value].Value = $argValue
}
else
{
$ArgumentList[$Index.Value] = $argValue
}
}
return $true
}
function HasParamsArray([System.Reflection.ParameterInfo[]] $ParameterList)
{
return $ParameterList.Count -gt 0 -and (IsParamsArray -ParameterInfo $ParameterList[-1])
}
function IsParamsArray([System.Reflection.ParameterInfo] $ParameterInfo)
{
return @($ParameterInfo.GetCustomAttributes([System.ParamArrayAttribute], $true)).Count -gt 0
}
function Resolve-RuntimeType
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Type]
$ParameterType,
[Parameter(Mandatory = $true)]
[Type[]]
$RuntimeType,
[Parameter(Mandatory = $true)]
[Type[]]
$GenericType
)
if ($ParameterType.IsByRef)
{
$elementType = Resolve-RuntimeType -ParameterType $ParameterType.GetElementType() -RuntimeType $RuntimeType -GenericType $GenericType
return $elementType.MakeByRefType()
}
elseif ($ParameterType.IsGenericParameter)
{
for ($i = 0; $i -lt $GenericType.Count; $i++)
{
if ($ParameterType -eq $GenericType[$i])
{
return $RuntimeType[$i]
}
}
}
elseif ($ParameterType.IsArray)
{
$arrayType = $ParameterType
$elementType = Resolve-RuntimeType -ParameterType $ParameterType.GetElementType() -RuntimeType $RuntimeType -GenericType $GenericType
if ($ParameterType.GetElementType().IsGenericParameter)
{
$arrayRank = $arrayType.GetArrayRank()
if ($arrayRank -eq 1)
{
$arrayType = $elementType.MakeArrayType()
}
else
{
$arrayType = $elementType.MakeArrayType($arrayRank)
}
}
return $arrayType
}
elseif ($ParameterType.ContainsGenericParameters)
{
$genericArguments = $ParameterType.GetGenericArguments()
$runtimeArguments = New-Object System.Collections.ArrayList
foreach ($argument in $genericArguments)
{
$null = $runtimeArguments.Add((Resolve-RuntimeType -ParameterType $argument -RuntimeType $RuntimeType -GenericType $GenericType))
}
$definition = $ParameterType
if (-not $definition.IsGenericTypeDefinition)
{
$definition = $definition.GetGenericTypeDefinition()
}
return $definition.MakeGenericType($runtimeArguments.ToArray())
}
else
{
return $ParameterType
}
}
function Get-Type($object)
{
if ($null -eq $object) { return $null }
return $object.GetType()
}
if (-not ([System.Management.Automation.PSTypeName]'PSGenericMethods.MethodInvoker').Type)
{
Add-Type -ErrorAction SilentlyContinue -TypeDefinition @'
namespace PSGenericMethods
{
using System;
using System.Reflection;
using System.Management.Automation;
public static class MethodInvoker
{
public static object InvokeMethod(MethodInfo method, object target, object[] arguments)
{
if (method == null) { throw new ArgumentNullException("method"); }
object[] args = null;
if (arguments != null)
{
args = (object[])arguments.Clone();
for (int i = 0; i < args.Length; i++)
{
PSObject pso = args[i] as PSObject;
if (pso != null)
{
args[i] = pso.BaseObject;
}
PSReference psref = args[i] as PSReference;
if (psref != null)
{
args[i] = psref.Value;
}
}
}
object result = method.Invoke(target, args);
for (int i = 0; i < arguments.Length; i++)
{
PSReference psref = arguments[i] as PSReference;
if (psref != null)
{
psref.Value = args[i];
}
}
return result;
}
}
}
'@
}
<#
.SYNOPSIS
Gets an Team Foundation Server REST API client object.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
#>
Function Get-TfsHttpClient
{
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string]
$Type,
[Parameter()]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection
return Invoke-GenericMethod -InputObject $tpc -MethodName GetClient -GenericType $Type
}
}
<#
.SYNOPSIS
Exports a process template definition to disk.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Export-TfsProcessTemplate
{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
[SupportsWildcards()]
[object]
$Process = "*",
[Parameter(Mandatory=$true)]
[string]
$DestinationPath,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$NewName,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]
$NewDescription,
[Parameter(ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$processTemplateSvc = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.IProcessTemplates")
if ($Process -is [Microsoft.TeamFoundation.Server.TemplateHeader])
{
$templates = @($Process)
}
else
{
$templates = Get-TfsProcessTemplate $Process -Collection $Collection
}
if ($NewName -or $NewDescription)
{
$templates = $templates | select -First 1
}
foreach($template in $templates)
{
if ($NewName)
{
$templateName = $NewName
}
else
{
$templateName = $template.Name
}
$tempFile = $processTemplateSvc.GetTemplateData($template.TemplateId)
$zipFile = "$tempFile.zip"
Rename-Item -Path $tempFile -NewName (Split-Path $zipFile -Leaf)
$outDir = Join-Path $DestinationPath $templateName
New-Item $outDir -ItemType Directory -Force | Out-Null
Expand-Archive -Path $zipFile -DestinationPath $outDir
if ($NewName -or $NewDescription)
{
$ptFile = (Join-Path $outDir "ProcessTemplate.xml")
$ptXml = [xml] (Get-Content $ptFile)
if ($NewName)
{
$ptXml.ProcessTemplate.metadata.name = $NewName
}
if ($NewDescription)
{
$ptXml.ProcessTemplate.metadata.description = $NewDescription
}
$ptXml.Save($ptFile)
}
Remove-Item $zipFile
}
}
}
<#
.SYNOPSIS
Gets information from one or more process templates.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Get-TfsProcessTemplate
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Server.TemplateHeader])]
Param
(
[Parameter(Position=0)]
[SupportsWildcards()]
[string]
$Name = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$processTemplateSvc = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.IProcessTemplates")
$templateHeaders = $processTemplateSvc.TemplateHeaders() | ? Name -Like $Name
foreach($templateHeader in $templateHeaders)
{
$templateHeader | Add-Member Collection $tpc.DisplayName -PassThru
}
}
}
<#
.SYNOPSIS
Imports a process template definition from disk.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function Import-TfsProcessTemplate
{
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]
$SourcePath,
[Parameter()]
[ValidateSet("Visible")]
[string]
$State = "Visible",
[Parameter()]
[object]
$Collection
)
Process
{
if (-Not (Test-Path (Join-Path $SourcePath "ProcessTemplate.xml")))
{
throw "Invalid path. Source path ""$SourcePath"" must be a directory and must contain a file named ProcessTemplate.xml."
}
$tpc = Get-TfsTeamProjectCollection $Collection
$processTemplateSvc = $tpc.GetService([type]"Microsoft.TeamFoundation.Server.IProcessTemplates")
$tempFile = New-TemporaryFile
$zipFile = "$tempFile.zip"
Rename-Item $tempFile -NewName (Split-Path $zipFile -Leaf)
Compress-Archive -Path "$SourcePath/**" -DestinationPath $zipFile -Force
$ptFile = (Join-Path $SourcePath "ProcessTemplate.xml")
$ptXml = [xml] (Get-Content $ptFile)
$name = $ptXml.ProcessTemplate.metadata.name
$description = $ptXml.ProcessTemplate.metadata.description
$metadata = $ptXml.ProcessTemplate.metadata.OuterXml
$processTemplateSvc.AddUpdateTemplate($name, $description, $metadata, $State, $zipFile);
Remove-Item $zipFile
}
}
$binDir = (Join-Path $PSScriptRoot 'lib')
$assemblyList = ''
foreach($a in Get-ChildItem $binDir)
{
$assemblyList += "{""$($a.BaseName)"", @""$($a.FullName)""},`r`n"
}
if (-not ([System.Management.Automation.PSTypeName]'TfsCmdlets.AssemblyResolver').Type)
{
Add-Type -ErrorAction SilentlyContinue -Language CSharp -TypeDefinition @"
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
namespace TfsCmdlets
{
public class AssemblyResolver
{
private static bool IsVerbose = ("$VerbosePreference" == "Continue");
public static readonly Dictionary<string, string> PrivateAssemblies = new Dictionary<string, string>
{
$assemblyList
};
public static readonly Dictionary<string, Assembly> LoadedAssemblies = new Dictionary<string, Assembly>();
public static readonly Dictionary<string, object> LogEntries = new Dictionary<string, object>();
public static void Register()
{
AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs e)
{
try
{
var assemblyName = e.Name.Split(',')[0];
var isInternal = PrivateAssemblies.ContainsKey(assemblyName);
if (IsVerbose) Log("[INFO ] [" + (isInternal? "Internal": "External") + "] " + assemblyName, e);
return PrivateAssemblies.ContainsKey(assemblyName)
? LoadAssembly(assemblyName)
: null;
}
catch(Exception ex)
{
LogError(ex);
return null;
}
};
}
private static Assembly LoadAssembly(string assemblyName)
{
var assembly = Assembly.LoadFrom(PrivateAssemblies[assemblyName]);
LoadedAssemblies.Add(assemblyName, assembly);
return assembly;
}
private static void Log(string message, object data)
{
message = "[" + (LogEntries.Count+1).ToString("00000") + "] [" + DateTime.Now.ToString("HH:mm:ss.fff") + "] " + message;
LogEntries.Add(message, data);
}
private static void LogError(Exception ex)
{
Log("[ERROR] " + ex.Message, ex);
}
}
}
"@
}
[TfsCmdlets.AssemblyResolver]::Register()
# Initialize Shell
if ($Host.UI.RawUI.WindowTitle -eq "Team Foundation Server Shell")
{
# SetConsoleColors
$Host.UI.RawUI.BackgroundColor = "DarkMagenta"
$Host.UI.RawUI.ForegroundColor = "White"
Clear-Host
# ShowBanner
$module = Test-ModuleManifest -Path (Join-Path $PSScriptRoot 'TfsCmdlets.psd1')
Write-Host "TfsCmdlets: $($module.Description)"
Write-Host "Version $($module.PrivateData.Build)"
Write-Host ""
@'
Function Prompt
{
Process
{
$tfsPrompt = ''
if ($global:TfsServerConnection)
{
$tfsPrompt = $global:TfsServerConnection.Name
if ($global:TfsTpcConnection)
{
$tfsPrompt += "/$($global:TfsTpcConnection.Name)"
}
if ($global:TfsProjectConnection)
{
$tfsPrompt += "/$($global:TfsProjectConnection.Name)"
}
if ($global:TfsTeamConnection)
{
$tfsPrompt += "/$($global:TfsTeamConnection.Name)"
}
$tfsPrompt = "[$tfsPrompt] "
}
"TFS $($tfsPrompt)$($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
}
}
'@ | Invoke-Expression
}
# Load basic TFS client assemblies
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.Common.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.Client.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.WorkItemTracking.Client.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.Build.Client.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.Git.Client.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.VersionControl.Client.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.Core.WebApi.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.TeamFoundation.SourceControl.WebApi.dll')
Add-Type -Path (Join-Path $BinDir 'Microsoft.VisualStudio.Services.WebApi.dll')
Function _GetTeam
{
param
(
[Parameter()]
[string]
$ProjectName,
[Parameter()]
[string]
$Name
)
Begin
{
$tpc = Get-TfsTeamProjectCollection -Current
$teamService = $tpc.GetService([type]"Microsoft.TeamFoundation.Client.TfsTeamService")
}
Process
{
$teamProject = Get-TfsTeamProject $projectName
$team = ($teamService.QueryTeams($teamProject.Uri) | where Name -eq $name)
return $team
}
}
Function _CreateTeam
{
param
(
)
Process
{
$teamService = $tpc.GetService([type]"Microsoft.TeamFoundation.Client.TfsTeamService")
return $teamService.CreateTeam($teamProject.Uri, $Name, $Description, $null)
}
}
Function _SetTeamSettings
{
param
(
$team,
[string[]]
$teamFieldValues
)
}
function _GetTfsTeamSettingsConfigurationService {
Param(
[Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $TfsCollection
)
return $TfsCollection.GetService([ Microsoft.TeamFoundation.ProcessConfiguration.Client.TeamSettingsConfigurationService]);
}
function _AddTfsTeamField {
Param(
[parameter(Mandatory=$true)][Microsoft.TeamFoundation.Client.TfsTeamProjectCollection] $TfsCollection,
[parameter(Mandatory=$true)][Microsoft.TeamFoundation.Server.ProjectInfo] $TfsTeamProject,
[parameter(Mandatory=$true)][Microsoft.TeamFoundation.Client.TeamFoundationTeam] $TfsTeam,
[parameter(Mandatory=$true)][String] $TeamFieldValue
)
$TfsTeamConfigService = Get-TfsTeamSettingsConfigurationService $TfsCollection
$TfsTeamConfig = $TfsTeamConfigService.GetTeamConfigurations([Guid[]]($TfsTeam.Identity.TeamFoundationId))
$newTeamFieldValue = New-Object Microsoft.TeamFoundation.ProcessConfiguration.Client.TeamFieldValue
$newTeamFieldValue.Value = $TeamFieldValue
$TfsTeamConfig.TeamSettings.TeamFieldValues = [Microsoft.TeamFoundation.ProcessConfiguration.Client.TeamFieldValue[]]($newTeamFieldValue)
$TfsTeamConfig.TeamSettings.BacklogIterationPath = "$($TfsTeamProject.Name)"
#$TfsTeamConfig.TeamSettings.IterationPaths = [string[]]("$($TfsTeamProject.Name)")
$TfsTeamConfigService.SetTeamSettings($TfsTeam.Identity.TeamFoundationId,$TfsTeamConfig.TeamSettings)
}
<#
.SYNOPSIS
Gets information about one or more teams.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsTeam
{
[CmdletBinding(DefaultParameterSetName="Get by name")]
[OutputType([Microsoft.TeamFoundation.Client.TeamFoundationTeam])]
param
(
[Parameter(Position=0, ParameterSetName="Get by name")]
[Alias("Name")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Client.TeamFoundationTeam])})]
[SupportsWildcards()]
[object]
$Team = '*',
[Parameter(Position=0, ParameterSetName="Get default team")]
[switch]
$Default,
[Parameter()]
[switch]
$IncludeMembers,
[Parameter()]
[Microsoft.TeamFoundation.Framework.Common.MembershipQuery]
$QueryMembership = [Microsoft.TeamFoundation.Framework.Common.MembershipQuery]::Direct,
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($Team -is [Microsoft.TeamFoundation.Client.TeamFoundationTeam])
{
return $Team
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$teamService = $tpc.GetService([type]'Microsoft.TeamFoundation.Client.TfsTeamService')
if ($Default)
{
$teams = @($teamService.GetDefaultTeam($tp.Uri, $null))
}
else
{
$teams = $teamService.QueryTeams([string]$tp.Uri) | ? Name -like $Team
}
foreach($t in $teams)
{
if ($IncludeMembers)
{
$members = $t.GetMembers($tpc, $QueryMembership)
$t | Add-Member -Name 'Members' -MemberType ([System.Management.Automation.PSMemberTypes]::NoteProperty) -Value $members -PassThru
}
else
{
$t | Add-Member -Name 'Members' -MemberType ([System.Management.Automation.PSMemberTypes]::NoteProperty) -Value ([Microsoft.TeamFoundation.Framework.Client.TeamFoundationIdentity[]] @()) -PassThru
}
}
}
}
<#
.SYNOPSIS
Creates a new team.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Passthru
Returns the results of the command. By default, this cmdlet does not generate any output.
.INPUTS
System.String
#>
Function New-TfsTeam
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Client.TeamFoundationTeam])]
param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[Alias("Name")]
[string]
$Team,
[Parameter()]
[string]
$Description,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection,
[Parameter()]
[switch]
$Passthru
)
Process
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$teamService = $tpc.GetService([type]"Microsoft.TeamFoundation.Client.TfsTeamService")
$newTeam = $teamService.CreateTeam($tp.Uri, $Team, $Description, $null)
if ($Passthru)
{
return $team
}
}
}
<#
.SYNOPSIS
Deletes a team.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TeamFoundationTeam
System.String
#>
Function Remove-TfsTeam
{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')]
[OutputType([Microsoft.TeamFoundation.Client.TeamFoundationTeam])]
param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[Alias("Name")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Client.TeamFoundationTeam])})]
[SupportsWildcards()]
[object]
$Team = '*',
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$t = Get-TfsTeam -Team $Team -Project $Project -Collection $Collection
if ($PSCmdlet.ShouldProcess($t.Name, 'Delete team'))
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$identityService = $tpc.GetService([type]'Microsoft.TeamFoundation.Framework.Client.IIdentityManagementService')
$identityService.DeleteApplicationGroup($t.Identity.Descriptor)
}
}
}
<#
.SYNOPSIS
Renames a team.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TeamFoundationTeam
System.String
#>
Function Rename-TfsTeam
{
[OutputType([Microsoft.TeamFoundation.Client.TeamFoundationTeam])]
param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[Alias("Name")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Client.TeamFoundationTeam])})]
[SupportsWildcards()]
[object]
$Team = '*',
[Parameter()]
[string]
$NewName,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
Set-TfsTeam -Team $Team -NewName $NewName -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Changes the details of a team.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TeamFoundationTeam
System.String
#>
Function Set-TfsTeam
{
[CmdletBinding(DefaultParameterSetName="Get by name")]
[OutputType([Microsoft.TeamFoundation.Client.TeamFoundationTeam])]
param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[Alias("Name")]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.Client.TeamFoundationTeam])})]
[SupportsWildcards()]
[object]
$Team = '*',
[Parameter()]
[switch]
$Default,
[Parameter()]
[string]
$NewName,
[Parameter()]
[string]
$Description,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$t = Get-TfsTeam -Team $Team -Project $Project -Collection $Collection
if ($Project)
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
}
else
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection
}
$teamService = $tpc.GetService([type]'Microsoft.TeamFoundation.Client.TfsTeamService')
if ($NewName)
{
$t.Name = $NewName
}
if ($PSBoundParameters.ContainsKey('Description'))
{
$t.Description = $Description
}
if ($Default)
{
$teamService.SetDefaultTeam($t)
}
$teamService.UpdateTeam($t)
return $t
}
}
<#
.SYNOPSIS
Gets information about one or more team projects.
.DESCRIPTION
The Get-TfsTeamProject cmdlets gets one or more Team Project objects (an instance of Microsoft.TeamFoundation.WorkItemTracking.Client.Project) from the supplied Team Project Collection.
.PARAMETER Project
Specifies the name of a Team Project. Wildcards are supported.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Server
Specifies either a URL or the name of the Team Foundation Server configuration server (the "root" of a TFS installation) to connect to, or a previously initialized Microsoft.TeamFoundation.Client.TfsConfigurationServer object.
For more details, see the -Server argument in the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
.NOTES
As with most cmdlets in the TfsCmdlets module, this cmdlet requires a TfsTeamProjectCollection object to be provided via the -Collection argument. If absent, it will default to the connection opened by Connect-TfsTeamProjectCollection.
#>
Function Get-TfsTeamProject
{
[CmdletBinding(DefaultParameterSetName='Get by project')]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.Project])]
Param
(
[Parameter(Position=0, ParameterSetName='Get by project')]
[object]
$Project = '*',
[Parameter(ValueFromPipeline=$true, Position=1, ParameterSetName='Get by project')]
[object]
$Collection,
[Parameter(Position=0, ParameterSetName="Get current")]
[switch]
$Current,
[Parameter()]
[object]
$Credential
)
Process
{
if ($Current)
{
return $global:TfsProjectConnection
}
if ($Project -is [Microsoft.TeamFoundation.WorkItemTracking.Client.Project])
{
return $Project
}
if (($Project -is [uri]) -or ([System.Uri]::IsWellFormedUriString($Project, [System.UriKind]::Absolute)))
{
$tpc = Get-TfsTeamProjectCollection $Collection -Credential $Credential
$css = $tpc.GetService([type]'Microsoft.TeamFoundation.Server.ICommonStructureService')
$projInfo = $css.GetProject([string] $Project)
$Project = $projInfo.Name
}
if ($Project -is [string])
{
$tpc = Get-TfsTeamProjectCollection $Collection -Credential $Credential
$wiStore = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
return _GetAllProjects $tpc | ? Name -Like $Project | % { $wiStore.Projects[$_.Name] }
}
if ($Project -eq $null)
{
if ($global:TfsProjectConnection)
{
return $global:TfsProjectConnection
}
}
throw "No TFS team project information available. Either supply a valid -Project argument or use Connect-TfsTeamProject prior to invoking this cmdlet."
}
}
Function _GetAllProjects
{
param ($tpc)
$css = $tpc.GetService([type]'Microsoft.TeamFoundation.Server.ICommonStructureService')
return $css.ListAllProjects() | ? Status -eq WellFormed
}
<#
.SYNOPSIS
Creates a new team project.
#>
Function New-TfsTeamProject
{
[CmdletBinding(DefaultParameterSetName='Get by project')]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.Project])]
Param
(
[Parameter(Position=0, Mandatory=$true)]
[string]
$Project,
[Parameter(ValueFromPipeline=$true, Position=1)]
[object]
$Collection,
[string]
$Description,
[string]
[ValidateSet('Git', 'TFVC')]
$SourceControl,
[object]
$ProcessTemplate
)
Process
{
$tpc = Get-TfsTeamProjectCollection $Collection
$template = Get-TfsProcessTemplate -Collection $tpc -Name $ProcessTemplate
$client = Get-TfsHttpClient 'Microsoft.TeamFoundation.Core.WebApi.ProjectHttpClient' -Collection $tpc
$tpInfo = New-Object 'Microsoft.TeamFoundation.Core.WebApi.TeamProject'
$tpInfo.Name = $Project
$tpInfo.Description = $Description
$tpInfo.Capabilities = New-Object 'System.Collections.Generic.Dictionary[[string],System.Collections.Generic.Dictionary[[string],[string]]]'
$tpInfo.Capabilities.Add('versioncontrol', (New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'))
$tpInfo.Capabilities['versioncontrol'].Add('sourceControlType', $SourceControl)
$tpInfo.Capabilities.Add('processTemplate', (New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'))
$tpInfo.Capabilities['processTemplate'].Add('templateTypeId', ([xml]$template.Metadata).metadata.version.type)
# Trigger the project creation
$token = $client.QueueCreateProject($tpInfo).Result
if (-not $token)
{
throw "Error queueing team project creation: $($client.LastResponseContext.Exception.Message)"
}
# Wait for the operation to complete
$operationsClient = Get-TfsHttpClient 'Microsoft.VisualStudio.Services.Operations.OperationsHttpClient' -Collection $tpc
$opsToken = $operationsClient.GetOperation($token.Id).Result
while (
($opsToken.Status -ne [Microsoft.VisualStudio.Services.Operations.OperationStatus]::Succeeded) -and
($opsToken.Status -ne [Microsoft.VisualStudio.Services.Operations.OperationStatus]::Failed) -and
($opsToken.Status -ne [Microsoft.VisualStudio.Services.Operations.OperationStatus]::Cancelled))
{
Start-Sleep -Seconds 2
$opsToken = $operationsClient.GetOperation($token.Id).Result
}
if ($opsToken.Status -ne [Microsoft.VisualStudio.Services.Operations.OperationStatus]::Succeeded)
{
throw "Error creating team project $Project"
}
# Force a metadata cache refresh prior to retrieving the newly created project
$wiStore = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
$wiStore.RefreshCache()
return Get-TfsTeamProject -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Detaches a team project collection database from a Team Foundation Server installation.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsConfigurationServer
System.String
System.Uri
#>
Function Dismount-TfsTeamProjectCollection
{
[CmdletBinding(ConfirmImpact="High", SupportsShouldProcess=$true)]
Param
(
[Parameter(Mandatory=$true, Position=0)]
[object]
$Collection,
[Parameter(ValueFromPipeline=$true)]
[object]
$Server,
[Parameter()]
[string]
$Reason,
[Parameter()]
[timespan]
$Timeout = [timespan]::MaxValue,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection -Server $Server -Credential $Credential
if ($PSCmdlet.ShouldProcess($tpc.Name, "Detach Project Collection"))
{
$configServer = $tpc.ConfigurationServer
$tpcService = $configServer.GetService([type] 'Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')
$collectionInfo = $tpcService.GetCollection($tpc.InstanceId)
$connectionString = $null
$tpcJob = $tpcService.QueueDetachCollection($collectionInfo, $null, $Reason, [ref] $connectionString)
$collectionInfo = $tpcService.WaitForCollectionServicingToComplete($tpcJob, $Timeout)
return $connectionString
}
}
}
<#
.SYNOPSIS
Gets one or more Team Project Collection addresses registered in the current computer.
.PARAMETER Name
Specifies the name of a registered collection. When omitted, all registered collections are returned. Wildcards are permitted.
.INPUTS
System.String
#>
Function Get-TfsRegisteredTeamProjectCollection
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Client.RegisteredProjectCollection[]])]
Param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[SupportsWildcards()]
[string]
$Name = "*"
)
Process
{
return [Microsoft.TeamFoundation.Client.RegisteredTfsConnections]::GetProjectCollections() | ? DisplayName -Like $Name
}
}
<#
.SYNOPSIS
Gets information about one or more team project collections.
.DESCRIPTION
The Get-TfsTeamProjectCollection cmdlets gets one or more Team Project Collection objects (an instance of Microsoft.TeamFoundation.Client.TfsTeamProjectCollection) from a TFS instance.
Team Project Collection objects can either be obtained by providing a fully-qualified URL to the collection or by collection name (in which case a TFS Configuration Server object is required).
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.PARAMETER Server
Specifies either a URL/name of the Team Foundation Server configuration server (the "root" of a TFS installation) to connect to, or a previously initialized Microsoft.TeamFoundation.Client.TfsConfigurationServer object.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the cached credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in. To provide a user name and password, and/or to open a input dialog to enter your credentials, call Get-TfsCredential with the appropriate arguments and pass its return to this argument. For more information, refer to https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.client.tfsclientcredentials.aspx
.EXAMPLE
Get-TfsTeamProjectCollection http://
.INPUTS
Microsoft.TeamFoundation.Client.TfsConfigurationServer
.NOTES
Cmdlets in the TfsCmdlets module that operate on a collection level require a TfsConfigurationServer object to be provided via the -Server argument. If absent, it will default to the connection opened by Connect-TfsConfigurationServer.
#>
Function Get-TfsTeamProjectCollection
{
[CmdletBinding(DefaultParameterSetName='Get by collection')]
[OutputType([Microsoft.TeamFoundation.Client.TfsTeamProjectCollection])]
Param
(
[Parameter(Position=0, ParameterSetName="Get by collection")]
[SupportsWildcards()]
[object]
$Collection = "*",
[Parameter(ValueFromPipeline=$true, ParameterSetName="Get by collection")]
[object]
$Server,
[Parameter(Position=0, ParameterSetName="Get current")]
[switch]
$Current,
[Parameter(ParameterSetName="Get by collection")]
[object]
$Credential
)
Process
{
if ($Current)
{
return $Global:TfsTpcConnection
}
if ($Collection -is [Microsoft.TeamFoundation.Client.TfsTeamProjectCollection])
{
return $Collection
}
if ($Collection -is [Uri])
{
return _GetCollectionFromUrl $Collection $Credential
}
if ($Collection -is [string])
{
if ([Uri]::IsWellFormedUriString($Collection, [UriKind]::Absolute))
{
return _GetCollectionFromUrl ([Uri] $Collection) $Credential
}
if (-not [string]::IsNullOrWhiteSpace($Collection))
{
return _GetCollectionFromName $Collection $Server $Credential
}
$Collection = $null
}
if ($Collection -eq $null)
{
if ($Global:TfsTpcConnection)
{
return $Global:TfsTpcConnection
}
}
throw "No TFS connection information available. Either supply a valid -Collection argument or use Connect-TfsTeamProjectCollection prior to invoking this cmdlet."
}
}
# =================
# Helper Functions
# =================
Function _GetCollectionFromUrl([uri] $Url, $Credential)
{
$cred = Get-TfsCredential -Credential $Credential
return New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection -ArgumentList $Url, $cred
}
Function _GetCollectionFromName($Name, $Server, $Credential)
{
$cred = Get-TfsCredential -Credential $Credential
$configServer = Get-TfsConfigurationServer $Server -Credential $Cred
$filter = [Guid[]] @([Microsoft.TeamFoundation.Framework.Common.CatalogResourceTypes]::ProjectCollection)
$collections = $configServer.CatalogNode.QueryChildren($filter, $false, [Microsoft.TeamFoundation.Framework.Common.CatalogQueryOptions]::IncludeParents)
$collections = $collections | Select -ExpandProperty Resource | ? DisplayName -like $Name
if ($collections.Count -eq 0)
{
throw "Invalid or non-existent Team Project Collection(s): $Name"
}
foreach($tpc in $collections)
{
$collectionId = $tpc.Properties["InstanceId"]
$tpc = $configServer.GetTeamProjectCollection($collectionId)
$tpc
}
}
<#
.SYNOPSIS
Attaches a team project collection database to a Team Foundation Server installation.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.INPUTS
Microsoft.TeamFoundation.Client.TfsConfigurationServer
System.String
System.Uri
#>
Function Mount-TfsTeamProjectCollection
{
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string]
$Name,
[Parameter()]
[string]
$Description,
[Parameter(ParameterSetName="Use database server", Mandatory=$true)]
[string]
$DatabaseServer,
[Parameter(ParameterSetName="Use database server", Mandatory=$true)]
[string]
$DatabaseName,
[Parameter(ParameterSetName="Use connection string", Mandatory=$true)]
[string]
$ConnectionString,
[Parameter()]
[ValidateSet("Started", "Stopped")]
[string]
$InitialState = "Started",
[Parameter()]
[switch]
$Clone,
[Parameter()]
[int]
$PollingInterval = 5,
[Parameter()]
[timespan]
$Timeout = [timespan]::MaxValue,
[Parameter(ValueFromPipeline=$true)]
[object]
$Server,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$configServer = Get-TfsConfigurationServer $Server -Credential $Credential
$tpcService = $configServer.GetService([type] 'Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')
$servicingTokens = New-Object 'System.Collections.Generic.Dictionary[string,string]'
if ($DatabaseName)
{
$servicingTokens["CollectionDatabaseName"] = $DatabaseName
}
if ($PSCmdlet.ParameterSetName -eq "Use database server")
{
$ConnectionString = "Data source=$DatabaseServer; Integrated Security=true; Initial Catalog=$DatabaseName"
}
try
{
Write-Progress -Id 1 -Activity "Attach team project collection" -Status "Attaching team project collection $Name" -PercentComplete 0
$start = Get-Date
# string databaseConnectionString, IDictionary<string, string> servicingTokens, bool cloneCollection, string name, string description, string virtualDirectory)
$tpcJob = $tpcService.QueueAttachCollection(
$ConnectionString,
$servicingTokens,
$Clone.ToBool(),
$Name,
$Description,
"~/$Name/")
[void] $tpcService.WaitForCollectionServicingToComplete($tpcJob, $Timeout)
return Get-TfsTeamProjectCollection -Server $Server -Credential $Credential -Collection $Name
}
finally
{
Write-Progress -Id 1 -Activity "Attach team project collection" -Completed
}
throw (New-Object 'System.TimeoutException' -ArgumentList "Operation timed out during creation of team project collection $Name")
}
}
<#
.SYNOPSIS
Creates a new team project collection.
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.INPUTS
System.String
#>
Function New-TfsTeamProjectCollection
{
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[string]
$Name,
[Parameter()]
[string]
$Description,
[Parameter(ParameterSetName="Use database server", Mandatory=$true)]
[string]
$DatabaseServer,
[Parameter(ParameterSetName="Use database server")]
[string]
$DatabaseName,
[Parameter(ParameterSetName="Use connection string", Mandatory=$true)]
[string]
$ConnectionString,
[Parameter()]
[switch]
$Default,
[Parameter()]
[switch]
$UseExistingDatabase,
[Parameter()]
[ValidateSet("Started", "Stopped")]
[string]
$InitialState = "Started",
[Parameter()]
[int]
$PollingInterval = 5,
[Parameter()]
[timespan]
$Timeout = [timespan]::MaxValue,
[Parameter()]
[object]
$Server,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$configServer = Get-TfsConfigurationServer $Server -Credential $Credential
$tpcService = $configServer.GetService([type] 'Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')
$servicingTokens = New-Object 'System.Collections.Generic.Dictionary[string,string]'
$servicingTokens["SharePointAction"] = "None"
$servicingTokens["ReportingAction"] = "None"
if ($DatabaseName)
{
$servicingTokens["CollectionDatabaseName"] = $DatabaseName
}
if ($UseExistingDatabase)
{
$servicingTokens["UseExistingDatabase"] = $UseExistingDatabase.ToBool()
}
if ($PSCmdlet.ParameterSetName -eq "Use database server")
{
$ConnectionString = "Data source=$DatabaseServer; Integrated Security=true"
}
try
{
Write-Progress -Id 1 -Activity "Create team project collection" -Status "Creating team project collection $Name" -PercentComplete 0
$start = Get-Date
$tpcJob = $tpcService.QueueCreateCollection(
$Name,
$Description,
$Default.ToBool(),
"~/$Name/",
[Microsoft.TeamFoundation.Framework.Common.TeamFoundationServiceHostStatus] $InitialState,
$servicingTokens,
$ConnectionString,
$null, # Default connection string
$null) # Default category connection strings
while((Get-Date).Subtract($start) -le $Timeout)
{
Start-Sleep -Seconds $PollingInterval
$collectionInfo = $tpcService.GetCollection($tpcJob.HostId, [Microsoft.TeamFoundation.Framework.Client.ServiceHostFilterFlags]::IncludeAllServicingDetails)
$jobDetail = $collectionInfo.ServicingDetails | ? JobId -eq $tpcJob.JobId
if (($jobDetail -eq $null) -or
(($jobDetail.JobStatus -ne [Microsoft.TeamFoundation.Framework.Client.ServicingJobStatus]::Queued) -and
($jobDetail.JobStatus -ne [Microsoft.TeamFoundation.Framework.Client.ServicingJobStatus]::Running)))
{
if ($jobDetail.Result -eq [Microsoft.TeamFoundation.Framework.Client.ServicingJobResult]::Failed -or
$jobDetail.JobStatus -eq [Microsoft.TeamFoundation.Framework.Client.ServicingJobStatus]::Failed)
{
throw "Error creating team project collection $Name : "
}
return Get-TfsTeamProjectCollection -Server $Server -Credential $Credential -Collection $Name
}
}
}
finally
{
Write-Progress -Id 1 -Activity "Create team project collection" -Completed
}
throw (New-Object 'System.TimeoutException' -ArgumentList "Operation timed out during creation of team project collection $Name")
}
}
<#
.SYNOPSIS
Deletes a team project collection
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Remove-TfsTeamProjectCollection
{
[CmdletBinding(ConfirmImpact="High", SupportsShouldProcess=$true)]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[object]
$Collection,
[Parameter()]
[object]
$Server,
[Parameter()]
[timespan]
$Timeout = [timespan]::MaxValue,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection -Server $Server -Credential $Credential
if ($PSCmdlet.ShouldProcess($tpc.Name, "Delete Team Project Collection"))
{
Write-Progress -Id 1 -Activity "Delete team project collection" -Status "Deleting $($tpc.Name)" -PercentComplete 0
try
{
$configServer = $tpc.ConfigurationServer
$tpcService = $configServer.GetService([type] 'Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')
$collectionInfo = $tpcService.GetCollection($tpc.InstanceId)
$collectionInfo.Delete()
}
finally
{
Write-Progress -Id 1 -Activity "Delete team project collection" -Completed
}
}
}
}
<#
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Start-TfsTeamProjectCollection
{
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[object]
$Collection,
[Parameter()]
[object]
$Server,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
throw "Not implemented"
}
}
<#
.PARAMETER Credential
Specifies a user account that has permission to perform this action. The default is the credential of the user under which the PowerShell process is being run - in most cases that corresponds to the user currently logged in.
Type a user name, such as 'User01' or 'Domain01\User01', or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.
To connect to Visual Studio Team Services you must either: enable Alternate Credentials for your user profile and supply that credential in this argument or omit this argument to have a logon being dialog displayed automatically.
For more information on Alternate Credentials for your Visual Studio Team Services account, please refer to https://msdn.microsoft.com/library/dd286572#setup_basic_auth.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Stop-TfsTeamProjectCollection
{
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[object]
$Collection,
[Parameter()]
[string]
$Reason,
[Parameter()]
[object]
$Server,
[Parameter()]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
Process
{
throw "Not implemented"
}
}
@{
Author = 'Igor Abade V. Leite'
CompanyName = 'Igor Abade V. Leite'
Copyright = '(c) 2014 Igor Abade V. Leite. All rights reserved.'
Description = 'PowerShell Cmdlets for TFS and VSTS'
RootModule = 'TfsCmdlets.psm1'
FunctionsToExport = '*-Tfs*'
GUID = 'bd4390dc-a8ad-4bce-8d69-f53ccf8e4163'
HelpInfoURI = 'https://github.com/igoravl/tfscmdlets/wiki/'
ModuleVersion = '1.0.0.894'
PowerShellVersion = '3.0'
TypesToProcess = "TfsCmdlets.Types.ps1xml"
FormatsToProcess = "TfsCmdlets.Format.ps1xml"
ScriptsToProcess = 'Startup.ps1'
NestedModules = @('Admin\Admin.psm1','AreaIteration\AreaIteration.psm1','ConfigServer\ConfigServer.psm1','Connection\Connection.psm1','Git\Git.psm1','GlobalList\GlobalList.psm1','ObjectHelper\ObjectHelper.psm1','ProcessTemplate\ProcessTemplate.psm1','Team\Team.psm1','TeamProject\TeamProject.psm1','TeamProjectCollection\TeamProjectCollection.psm1','WorkItem\WorkItem.psm1','WorkItemQuery\WorkItemQuery.psm1','XamlBuild\XamlBuild.psm1')
FileList = @('chocolateyInstall.ps1','chocolateyUninstall.ps1','Startup.ps1','TfsCmdlets.Format.ps1xml','TfsCmdlets.psd1','TfsCmdlets.psm1','TfsCmdlets.Types.ps1xml','TfsCmdletsShell.ico')
PrivateData = @{
Tags = @('TfsCmdlets', 'TFS', 'VSTS', 'PowerShell')
Branch = 'master'
Commit = 'ab1fd619534c3cccaf2ba1d6d81a80be8bd7dccc'
Build = '1.0.0-beta1+20170405.894'
PreRelease = 'beta1'
LicenseUri = 'https://raw.githubusercontent.com/igoravl/tfscmdlets/master/LICENSE.md'
ProjectUri = 'https://github.com/igoravl/tfscmdlets/'
IconUri = 'https://raw.githubusercontent.com/igoravl/tfscmdlets/master/TfsCmdlets/resources/TfsCmdlets_Icon_32.png'
ReleaseNotes = 'See https://github.com/igoravl/tfscmdlets/wiki/ReleaseNotes'
TfsClientVersion = 'Microsoft.TeamFoundationServer.ExtendedClient 15.112.1'
}
}
Set-Alias tfsrv Connect-TfsConfigurationServer
Set-Alias tftpc Connect-TfsTeamProjectCollection
Set-Alias tftp Connect-TfsTeamProject
Set-Alias gtftpc Get-TfsTeamProjectCollection
Set-Alias gtftp Get-TfsTeamProject
Function _FixAreaIterationValues([hashtable] $Fields, $ProjectName)
{
if ($Fields.ContainsKey('System.AreaPath') -and ($Fields['System.AreaPath'] -notmatch "'\\?$ProjectName\\.+'"))
{
$Fields['System.AreaPath'] = ("$ProjectName\$($Fields['System.AreaPath'])" -replace '\\', '\')
}
if ($Fields.ContainsKey('System.IterationPath') -and ($Fields['System.IterationPath'] -notmatch "'\\?$ProjectName\\.+'"))
{
$Fields['System.IterationPath'] = ("$ProjectName\$($Fields['System.IterationPath'])" -replace '\\', '\')
}
return $Fields
}
<#
.SYNOPSIS
Gets the links of a work item.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Add-TfsWorkItemLink
{
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("id")]
[Alias("From")]
[ValidateNotNull()]
[object]
$SourceWorkItem,
[Parameter(Position=1, Mandatory=$true)]
[Alias("To")]
[ValidateNotNull()]
[object]
$TargetWorkItem,
[Parameter(Position=2, Mandatory=$true)]
[Alias("LinkType")]
[Alias("Type")]
[object]
$EndLinkType,
[Parameter()]
[string]
$Comment,
[switch]
$SkipSave,
[Parameter()]
[object]
$Collection
)
Process
{
$sourceWi = Get-TfsWorkItem -WorkItem $SourceWorkItem -Collection $Collection -Project $Project
$targetWi = Get-TfsWorkItem -WorkItem $TargetWorkItem -Collection $Collection -Project $Project
if ($EndLinkType -isnot [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLinkTypeEnd])
{
try
{
$EndLinkType = $sourceWi.Store.WorkItemLinkTypes.LinkTypeEnds[$EndLinkType]
}
catch
{
throw "Error retrieving work item link type $EndLinkType`: $_"
}
}
$link = New-Object 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink' -ArgumentList $EndLinkType, $targetWi.Id
$link.Comment = $Comment
$i = $sourceWi.WorkItemLinks.Add($link)
if (-not $SkipSave)
{
$sourceWi.Save()
}
return $sourceWi.WorkItemLinks[$i]
}
}
<#
.SYNOPSIS
Creates a copy of a work item, optionally changing its type
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
#>
Function Copy-TfsWorkItem
{
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipeline=$true)]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter()]
[object]
$Type,
[Parameter()]
[object]
$Project,
[Parameter()]
[switch]
$IncludeAttachments,
[Parameter()]
[switch]
$IncludeLinks,
[Parameter()]
[switch]
$SkipSave,
[Parameter()]
[ValidateSet('None', 'Original', 'Copy')]
[string]
$Passthru = 'None',
[Parameter()]
[object]
$Collection
)
Process
{
$wi = Get-TfsWorkItem -WorkItem $WorkItem -Collection $Collection
$store = $wi.Store
if($Type)
{
if ($Project)
{
$tp = $Project
}
else
{
$tp = $wi.Project
}
$witd = Get-TfsWorkItemType -Type $Type -Project $tp -Collection $wi.Store.TeamProjectCollection
}
else
{
$witd = $wi.Type
}
$flags = [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCopyFlags]::None
if ($IncludeAttachments)
{
$flags = $flags -bor [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCopyFlags]::CopyFiles
}
if ($IncludeLinks)
{
$flags = $flags -bor [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCopyFlags]::CopyLinks
}
$copy = $wi.Copy($witd, $flags)
if(-not $SkipSave)
{
$copy.Save()
}
if ($Passthru -eq 'Original')
{
return $wi
}
if($Passthru -eq 'Copy')
{
return $copy
}
}
}
<#
.SYNOPSIS
Exports a work item type definition from a team project to XML.
.PARAMETER Name
Uses this parameter to filter for an specific Work Item Type.
If suppress, cmdlet will return all Work Item Types on XML format.
.PARAMETER IncludeGlobalLists
Exports the definitions of referenced global lists. If not specified, global list definitions are omitted.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Export-TfsWorkItemType
{
[CmdletBinding()]
[OutputType([Xml])]
Param
(
[Parameter()]
[SupportsWildcards()]
[string]
$Name = "*",
[Parameter()]
[switch]
$IncludeGlobalLists,
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$types = Get-TfsWorkItemType -Name $Name -Project $Project -Collection $Collection
foreach($type in $types)
{
$type.Export($IncludeGlobalLists)
}
}
}
<#
.SYNOPSIS
Gets the contents of one or more work items.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsWorkItem
{
[CmdletBinding(DefaultParameterSetName="Query by text")]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])]
Param
(
[Parameter(Position=0, Mandatory=$true, ParameterSetName="Query by revision")]
[Parameter(Position=0, Mandatory=$true, ParameterSetName="Query by date")]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter(ParameterSetName="Query by revision")]
[Alias("rev")]
[int]
$Revision,
[Parameter(Mandatory=$true, ParameterSetName="Query by date")]
[datetime]
$AsOf,
[Parameter(Mandatory=$true, ParameterSetName="Query by WIQL")]
[Alias('WIQL')]
[Alias('QueryText')]
[Alias('SavedQuery')]
[Alias('QueryPath')]
[string]
$Query,
[Parameter(Mandatory=$true, ParameterSetName="Query by filter")]
[string]
$Filter,
[Parameter(Position=0, Mandatory=$true, ParameterSetName="Query by text")]
[string]
$Text,
[Parameter()]
[hashtable]
$Macros,
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($Project)
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$store = $tp.Store
}
else
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
}
if ($WorkItem -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])
{
if ((-Not $Revision) -and (-Not $AsOf))
{
return $WorkItem
}
}
switch($PSCmdlet.ParameterSetName)
{
"Query by revision" {
return _GetWorkItemByRevision $WorkItem $Revision $store
}
"Query by date" {
return _GetWorkItemByDate $WorkItem $AsOf $store
}
"Query by text" {
$localMacros = @{TfsQueryText=$Text}
$Wiql = "SELECT * FROM WorkItems WHERE [System.Title] CONTAINS @TfsQueryText OR [System.Description] CONTAINS @TfsQueryText"
return _GetWorkItemByWiql $Wiql $localMacros $tp $store
}
"Query by filter" {
$Wiql = "SELECT * FROM WorkItems WHERE $Filter"
return _GetWorkItemByWiql $Wiql $Macros $tp $store
}
"Query by WIQL" {
Write-Verbose "Get-TfsWorkItem: Running query by WIQL. Query: $Query"
return _GetWorkItemByWiql $Query $Macros $tp $store
}
"Query by saved query" {
return _GetWorkItemBySavedQuery $StoredQueryPath $Macros $tp $store
}
}
}
}
Function _GetWorkItemByRevision($WorkItem, $Revision, $store)
{
if ($WorkItem -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])
{
$ids = @($WorkItem.Id)
}
elseif ($WorkItem -is [int])
{
$ids = @($WorkItem)
}
elseif ($WorkItem -is [int[]])
{
$ids = $WorkItem
}
else
{
throw "Invalid work item ""$WorkItem"". Supply either a WorkItem object or one or more integer ID numbers"
}
if ($Revision -is [int] -and $Revision -gt 0)
{
foreach($id in $ids)
{
$store.GetWorkItem($id, $Revision)
}
}
elseif ($Revision -is [int[]])
{
if ($ids.Count -ne $Revision.Count)
{
throw "When supplying a list of IDs and Revisions, both must have the same number of elements"
}
for($i = 0; $i -le $ids.Count-1; $i++)
{
$store.GetWorkItem($ids[$i], $Revision[$i])
}
}
else
{
foreach($id in $ids)
{
$store.GetWorkItem($id)
}
}
}
Function _GetWorkItemByDate($WorkItem, $AsOf, $store)
{
if ($WorkItem -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])
{
$ids = @($WorkItem.Id)
}
elseif ($WorkItem -is [int])
{
$ids = @($WorkItem)
}
elseif ($WorkItem -is [int[]])
{
$ids = $WorkItem
}
else
{
throw "Invalid work item ""$WorkItem"". Supply either a WorkItem object or one or more integer ID numbers"
}
if ($AsOf -is [datetime[]])
{
if ($ids.Count -ne $AsOf.Count)
{
throw "When supplying a list of IDs and Changed Dates (AsOf), both must have the same number of elements"
}
for($i = 0; $i -le $ids.Count-1; $i++)
{
$store.GetWorkItem($ids[$i], $AsOf[$i])
}
}
else
{
foreach($id in $ids)
{
$store.GetWorkItem($id, $AsOf)
}
}
}
Function _GetWorkItemByWiql($QueryText, $Macros, $Project, $store)
{
if ($QueryText -notlike 'select*')
{
$q = Get-TfsWorkItemQuery -Query $QueryText -Project $Project
if (-not $q)
{
throw "Work item query '$QueryText' is invalid or non-existent."
}
if ($q.Count -gt 1)
{
throw "Ambiguous query name '$QueryText'. $($q.Count) queries were found matching the specified name/pattern:`n`n - " + ($q -join "`n - ")
}
$QueryText = $q.QueryText
}
if (-not $Macros -and (($QueryText -match "@project") -or ($QueryText -match "@me")))
{
$Macros = @{}
}
if ($QueryText -match "@project")
{
if (-not $Project)
{
$Project = Get-TfsTeamProject -Current
}
if (-not $Macros.ContainsKey("Project"))
{
$Macros["Project"] = $Project.Name
}
}
if ($QueryText -match "@me")
{
$user = $null
$store.TeamProjectCollection.GetAuthenticatedIdentity([ref] $user)
$Macros["Me"] = $user.DisplayName
}
Write-Verbose "Get-TfsWorkItem: Running query $QueryText"
$wis = $store.Query($QueryText, $Macros)
foreach($wi in $wis)
{
$wi
}
}
<#
.SYNOPSIS
Gets the history of changes of a work item.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
Get-TfsWorkItem -Filter '[System.WorkItemType] = "Task"' | % { Write-Output "WI $($_.Id): $($_.Title)"; Get-TfsWorkItemHistory -WorkItem $_ }
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem
System.Int32
#>
Function Get-TfsWorkItemHistory
{
[CmdletBinding()]
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter()]
[object]
$Collection
)
Process
{
$wi = Get-TfsWorkItem -WorkItem $WorkItem -Collection $Collection
$latestRev = $wi.Revisions.Count - 1
0..$latestRev | % {
$rev = $wi.Revisions[$_]
[PSCustomObject] @{
Revision = $_ + 1;
ChangedDate = $rev.Fields['System.ChangedDate'].Value
ChangedBy = $rev.Fields['System.ChangedBy'].Value
Changes = _GetChangedFields $wi $_
}
}
}
}
Function _GetChangedFields([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem] $wi, [int] $rev)
{
$result = @{}
$wi.Revisions[$rev].Fields | ? IsChangedInRevision -eq $true | % {
$result[$_.ReferenceName] = [PSCustomObject] @{
NewValue = $_.Value;
OriginalValue = $_.OriginalValue
}
}
return $result
}
<#
.SYNOPSIS
Gets the links of a work item.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsWorkItemLink
{
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.Link])]
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter()]
[object]
$Collection
)
Process
{
$wi = Get-TfsWorkItem -WorkItem $WorkItem -Collection $Collection
if ($wi)
{
return $wi.Links
}
}
}
<#
.SYNOPSIS
Gets the work item link end types of a team project collection.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
#>
Function Get-TfsWorkItemLinkEndType
{
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLinkTypeEnd])]
Param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection
return $tpc.WorkItemStore.WorkItemLinkTypes.LinkTypeEnds
}
}
<#
.SYNOPSIS
Gets one or more Work Item Type definitions from a team project.
.PARAMETER Name
Uses this parameter to filter for an specific Work Item Type.
If suppress, cmdlet will show all Work Item Types.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
Get-TfsWorkItemType -Name "Task" -Project "My Team Project"
Get informations about Work Item Type "Task" of a team project name "My Team Project"
.EXAMPLE
Get-TfsWorkItemType -Project "My Team Project"
Get all Work Item Types of a team project name "My Team Project"
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsWorkItemType
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType])]
Param
(
[Parameter(Position=0)]
[SupportsWildcards()]
[Alias("Name")]
[object]
$Type = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($Type -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType])
{
return $Type
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
return $tp.WorkItemTypes | ? Name -Like $Type
}
}
<#
.SYNOPSIS
Imports a work item type definition to a team project from XML.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.Xml.XmlDocument
#>
Function Import-TfsWorkItemType
{
[CmdletBinding()]
Param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[xml]
$Xml,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$tp = Get-TfsTeamProject $Project $Collection
$tp.WorkItemTypes.Import($Xml.OuterXml)
}
}
<#
.SYNOPSIS
Creates a new work item in a team project.
.PARAMETER Type
Represents the name of the work item type to create.
.PARAMETER Title
Specifies a Title field of new work item type that will be created.
.PARAMETER Fields
Specifies the fields that are changed and the new values to give to them.
FieldN The name of a field to update.
ValueN The value to set on the fieldN.
[field1=value1[;field2=value2;...]
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
New-TfsWorkItem -Type Task -Title "Task 1" -Project "MyTeamProject"
This example creates a new Work Item on Team Project "MyTeamProject".
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType
System.String
#>
Function New-TfsWorkItem
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])]
Param
(
[Parameter(ValueFromPipeline=$true, Mandatory=$true, Position=0)]
[object]
$Type,
[Parameter(Position=1)]
[string]
$Title,
[Parameter()]
[hashtable]
$Fields,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$wit = Get-TfsWorkItemType -Type $Type -Project $Project -Collection $Collection
$wi = $wit.NewWorkItem()
if ($Title)
{
$wi.Title = $Title
}
foreach($field in $Fields)
{
$wi.Fields[$field.Key] = $field.Value
}
$wi.Save()
return $wi
}
}
<#
.SYNOPSIS
Deletes a work item from a team project collection.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem
System.Int32
#>
Function Remove-TfsWorkItem
{
[CmdletBinding(ConfirmImpact="High", SupportsShouldProcess=$true)]
Param
(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter()]
[object]
$Collection
)
Process
{
$ids = @()
foreach($wi in $WorkItem)
{
if ($WorkItem -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])
{
$id = $WorkItem.Id
}
elseif ($WorkItem -is [int])
{
$id = $WorkItem
}
else
{
throw "Invalid work item ""$WorkItem"". Supply either a WorkItem object or one or more integer ID numbers"
}
if ($PSCmdlet.ShouldProcess("ID: $id", "Destroy workitem"))
{
$ids += $id
}
}
if ($ids.Count -gt 0)
{
$tpc = Get-TfsTeamProjectCollection $Collection
$store = $tpc.GetService([type] "Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$errors = $store.DestroyWorkItems([int[]] $ids)
if ($errors -and ($errors.Count -gt 0))
{
$errors | Write-Error "Error $($_.Id): $($_.Exception.Message)"
throw "Error destroying one or more work items"
}
}
}
}
<#
.SYNOPSIS
Sets the contents of one or more work items.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
#>
Function Set-TfsWorkItem
{
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipeline=$true, Position=0)]
[Alias("id")]
[ValidateNotNull()]
[object]
$WorkItem,
[Parameter(Position=1)]
[hashtable]
$Fields,
[Parameter()]
[switch]
$BypassRules,
[Parameter()]
[switch]
$SkipSave,
[Parameter()]
[object]
$Collection
)
Process
{
if ($WorkItem -is [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem])
{
$tpc = $WorkItem.Store.TeamProjectCollection
$id = $WorkItem.Id
}
else
{
$tpc = Get-TfsTeamProjectCollection -Collection $Collection
$id = (Get-TfsWorkItem -WorkItem $WorkItem -Collection $Collection).Id
}
if ($BypassRules)
{
$store = New-Object 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore' -ArgumentList $tpc, [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStoreFlags]::BypassRules
}
else
{
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
}
$wi = $store.GetWorkItem($id)
$Fields = _FixAreaIterationValues -Fields $Fields -ProjectName $wi.Project.Name
foreach($fldName in $Fields.Keys)
{
$wi.Fields[$fldName].Value = $Fields[$fldName]
}
if(-not $SkipSave)
{
$wi.Save()
}
return $wi
}
}
Function _FindQueryFolder($folder, $parent)
{
Write-Verbose "_FindQueryFolder: Searching for $folder under $($parent.Path)"
if ($folder -is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder])
{
Write-Verbose "_FindQueryFolder: Returning folder immediately, since it's a QueryFolder object"
return $folder
}
$folders = $parent | ? {$_ -Is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder]}
foreach($f in $folders)
{
if (($f.Path -like $folder) -or ($f.Name -like $folder))
{
Write-Verbose "_FindQueryFolder: Found folder `"$($f.Path)`" matching `"$folder`""
return @{$f.Name = $f}
}
}
foreach($f in $folders)
{
Write-Verbose "_FindQueryFolder: Starting recursive search"
$result = _FindQueryFolder $folder $f
if ($result)
{
return $result
}
}
}
Function _FindQuery($path, $parent)
{
Write-Verbose "_FindQuery: Searching for $path under $($parent.Path)"
foreach($item in $parent)
{
if (($item -Is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition]) -and (($item.Path -like $path) -or ($item.Name -like $path)))
{
# Search immediate children
Write-Verbose "_FindQuery: Found local query `"$($item.Path)`" matching `"$path`""
$item
}
elseif ($item -Is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryFolder])
{
# Search descendants recursively
Write-Verbose "_FindQuery: Starting recursive search"
_FindQuery $path $item
}
else
{
Write-Verbose "_FindQuery: Skipped `"$($item.Path)`" since it doesn't match $path"
}
}
}
Function _NormalizeQueryPath($Path, $ProjectName)
{
if([string]::IsNullOrWhiteSpace($Path))
{
return [string]::Empty
}
$newPath = [System.Text.RegularExpressions.Regex]::Replace($Path, '//{2,}', '/')
if ($newPath.StartsWith("/"))
{
$newPath = $newPath.Substring(1)
}
if ($newPath.EndsWith('/'))
{
$newPath = $newPath.Substring(0, $newPath.Length-1)
}
if ($newPath -notlike "$ProjectName*")
{
$newPath = "$ProjectName/$newPath"
}
return $newPath
}
<#
.SYNOPSIS
Exports a saved work item query to XML.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection
System.String
System.Uri
#>
Function Export-TfsWorkItemQuery
{
[CmdletBinding()]
[OutputType([xml])]
Param
(
[Parameter(ValueFromPipeline=$true)]
[SupportsWildcards()]
[string]
$Query = "*",
[Parameter()]
[string]
$Folder,
[Parameter()]
[string]
$Destination,
[Parameter()]
[string]
$Encoding = "UTF-8",
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($Destination -and (-not (Test-Path $Destination -PathType Container)))
{
throw "Invalid destination path $Destination"
}
$queries = Get-TfsWorkItemQuery -Query $Query -Folder $Folder -Project $Project -Collection $Collection
if (-not $queries)
{
throw "Query path `"$Query`" is invalid or missing."
}
foreach($q in $queries)
{
$xml = [xml] @"
<?xml version="1.0" encoding="$Encoding"?>
<!-- Original Query Path: $($q.Path) -->
<WorkItemQuery Version="1">
<TeamFoundationServer>$($q.Project.Store.TeamProjectCollection.Uri)</TeamFoundationServer>
<TeamProject>$($q.Project.Name)</TeamProject>
<Wiql><![CDATA[$($q.QueryText)]]></Wiql>
</WorkItemQuery>
"@
if (-not $Destination)
{
$xml
}
else
{
$queryPath = $q.Path.Substring($q.Path.IndexOf('/')+1)
$fileName = Join-Path $Destination "$queryPath.wiql"
$filePath = Split-Path $fileName -Parent
if (-not (Test-Path $filePath -PathType Container))
{
md $filePath -Force | Out-Null
}
$xml.Save($fileName)
}
}
}
}
<#
.SYNOPSIS
Gets the definition of one or more work item saved queries.
.PARAMETER Query
Specifies the path of a saved query. Wildcards are supported.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Get-TfsWorkItemQuery
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition])]
Param
(
[Parameter(Position=0)]
[ValidateNotNull()]
[SupportsWildcards()]
[Alias("Path")]
[object]
$Query = '*',
[Parameter()]
$Folder,
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if($Query -is [Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition])
{
return $Query
}
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
if ($Folder)
{
if (($Folder -is [string]) -and ($Folder -notlike "$($tp.Name)/*"))
{
$Folder = _NormalizeQueryPath $Folder $tp.Name
}
Write-Verbose "Get-TfsWorkItemQuery: Limiting search to folder $Folder"
$folders = (_FindQueryFolder $Folder $tp.QueryHierarchy)
if (-not $folders)
{
throw "Query folder $Folder is invalid or missing. Be sure you provided the full path (e.g. 'Shared Queries/Current Iteration') instead of just the folder name ('Current Iteration')"
}
$root = $folders.Values[0]
}
else
{
Write-Verbose "Get-TfsWorkItemQuery: -Folder argument missing. Searching entire team project"
$root = $tp.QueryHierarchy
}
return _FindQuery $Query $root
}
}
<#
.SYNOPSIS
Create a new work items query in the given Team Project.
.PARAMETER Query
Specifies the path of the new work item query.
When supplying a path, use a slash ("/") between the path segments. Leading and trailing backslashes are optional. The last segment in the path will be the area name.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
System.String
#>
Function New-TfsWorkItemQuery
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Name")]
[Alias("Path")]
[string]
$Query,
[Parameter()]
[string]
$Folder,
[Parameter()]
[string]
$Definition,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$tp = Get-TfsTeamProject -Project $Project -Collection $Collection
$tpc = $tp.Store.TeamProjectCollection
$store = $tp.Store
$Query = _NormalizeQueryPath "$Folder/$Query" $tp.Name
$folderPath = (Split-Path $Query -Parent) -replace ('\\', '/')
$queryName = (Split-Path $Query -Leaf)
Write-Verbose "New-TfsWorkItemQuery: Creating query '$queryName' in folder '$folderPath'"
$folder = (_FindQueryFolder $folderPath $tp.QueryHierarchy $true)
if (-not $folder)
{
throw "Invalid or non-existent work item query folder $folderPath."
}
if ($Definition -match "select \*")
{
Write-Warning "Queries containing 'SELECT *' may not work in Visual Studio. Consider replacing * with a list of fields."
}
$q = New-Object 'Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition' -ArgumentList $queryName, $Definition
$folder.Values[0].Add($q)
$tp.QueryHierarchy.Save()
return $q
}
}
<#
.SYNOPSIS
Deletes one or more work item queries from the specified Team Project..
.PARAMETER Query
Specifies the path of a saved query. Wildcards are supported.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Remove-TfsWorkItemQuery
{
[CmdletBinding(ConfirmImpact='High', SupportsShouldProcess=$true)]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[Alias("Path")]
[ValidateNotNull()]
[object]
$Query,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$queries = Get-TfsWorkItemQuery -Query $Query -Project $Project -Collection $Collection
foreach($q in $queries)
{
if ($PSCmdlet.ShouldProcess($q.Path, "Delete Query"))
{
$q.Delete()
}
}
}
}
<#
.SYNOPSIS
Changes the value of a property of an Area.
.PARAMETER Area
Specifies the name, URI or path of an Area. Wildcards are permitted. If omitted, all Areas in the given Team Project are returned.
To supply a path, use a backslash ('\') between the path segments. Leading and trailing backslashes are optional.
When supplying a URI, use URIs in the form of 'vstfs:///Classification/Node/<GUID>' (where <GUID> is the unique identifier of the given node)
.PARAMETER NewName
Specifies the new name of the area. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the area parameter, Rename-Tfsarea generates an error. To rename and move an item, use the Move-Tfsarea cmdlet.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.Project
System.String
#>
Function Rename-TfsWorkItemQuery
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNull()]
[Alias("Path")]
[object]
$Query,
[Parameter()]
[string]
$NewName,
[Parameter()]
[string]
$Definition,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
Set-TfsWorkItemQuery -Query $Query -NewName $NewName -Project $Project -Collection $Collection
}
}
<#
.SYNOPSIS
Changes the value of a property of a work item query.
.PARAMETER Query
Specifies the path of a work item saved query.
.PARAMETER NewName
Specifies the new name of the query. Enter only a name, not a path and name. If you enter a path that is different from the path that is specified in the area parameter, Rename-TfsWorkItemQuery generates an error. To rename and move an item, use the Move-TfsWorkItemQuery cmdlet instead.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.INPUTS
Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition
System.String
#>
Function Set-TfsWorkItemQuery
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.WorkItemTracking.Client.QueryDefinition])]
Param
(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[ValidateNotNull()]
[Alias("Path")]
[object]
$Query,
[Parameter()]
[string]
$NewName,
[Parameter()]
[string]
$Definition,
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
$q = Get-TfsWorkItemQuery -Query $Query -Project $Project -Collection $Collection
if (-not $q)
{
throw "Invalid or non-existent work item query $queries"
}
if ($q.Count -ne 1)
{
throw "Ambiguous query name '$Query'. $($q.Count) queries were found matching the specified name/pattern:`n`n - " + ($q -join "`n - ")
}
if ($NewName)
{
$q.Name = $NewName
}
if ($Definition)
{
$q.QueryText = $Definition
}
$q.Project.QueryHierarchy.Save()
return $q
}
}
<#
.SYNOPSIS
Gets information about one or more XAML Build agents.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
#>
Function Get-TfsXamlBuildAgent
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Build.Client.IBuildAgent])]
Param
(
[Parameter(Position=0)]
[ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent]})]
[ValidateNotNullOrEmpty()]
[Alias("Name")]
[object]
$BuildAgent = "*",
[Parameter(Position=0, ValueFromPipeline=$true)]
[ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})]
[ValidateNotNullOrEmpty()]
[Alias("Controller")]
[object]
$BuildController = "*",
[Parameter()]
[object]
$Collection
)
Process
{
if ($BuildAgent -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent])
{
return $BuildAgent
}
$controllers = Get-TfsXamlBuildController -BuildController $BuildController -Collection $Collection
foreach($controller in $controllers)
{
$controller.Agents | Where Name -Like $BuildAgent
}
}
}
<#
.SYNOPSIS
Gets information about one or more XAML Build controllers.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
#>
Function Get-TfsXamlBuildController
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Build.Client.IBuildController])]
Param
(
[Parameter(Position=0)]
[ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})]
[ValidateNotNullOrEmpty()]
[Alias("Name")]
[object]
$BuildController = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Collection
)
Process
{
if ($BuildController -is [Microsoft.TeamFoundation.Build.Client.IBuildController])
{
return $BuildController
}
$tpc = Get-TfsTeamProjectCollection $Collection
$buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
$buildControllers = $buildServer.QueryBuildControllers()
return $buildControllers | Where Name -Like $BuildController
}
}
<#
.SYNOPSIS
Gets one or more XAML Build definitions.
.PARAMETER BuildDefinition
Uses this parameter to filter for an specific Build Defintion.
If suppress, cmdlet will show all queue builds.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project"
Get all queued builds given a definition name and a team project name
.EXAMPLE
Get-TfsBuildQueue
Get all queued builds, regardless of definition name or team project name
#>
Function Get-TfsXamlBuildDefinition
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Build.Client.IBuildDefinition])]
Param
(
[Parameter(Position=0)]
[ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})]
[ValidateNotNullOrEmpty()]
[Alias("Name")]
[object]
$BuildDefinition = "*",
[Parameter(ValueFromPipeline=$true)]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
{
return $BuildDefinition
}
$tp = Get-TfsTeamProject $Project $Collection
$tpName = $tp.Name
$tpc = $tp.Store.TeamProjectCollection
$buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
$buildDefs = $buildServer.QueryBuildDefinitions($tpName)
return $buildDefs | Where Name -Like $BuildDefinition
}
}
<#
.SYNOPSIS
Gets information about queued XAML Builds.
.PARAMETER BuildDefinition
Uses this parameter to filter for an specific Build Defintion.
If suppress, cmdlet will show all queue builds.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project"
Get all queued builds given a definition name and a team project name
.EXAMPLE
Get-TfsBuildQueue
Get all queued builds, regardless of definition name or team project name
#>
Function Get-TfsXamlBuildQueue
{
[CmdletBinding()]
[OutputType([Microsoft.TeamFoundation.Build.Client.IQueuedBuild])]
Param
(
[Parameter(Position=0, ValueFromPipeline=$true)]
[ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})]
[ValidateNotNullOrEmpty()]
[object]
$BuildDefinition = "*",
[Parameter()]
[object]
$Project,
[Parameter()]
[object]
$Collection
)
Process
{
if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
{
$buildDefName = $BuildDefinition.Name
}
else
{
$buildDefName = $BuildDefinition
}
if ($Project)
{
$tp = Get-TfsTeamProject $Project $Collection
$tpName = $tp.Name
$tpc = $tp.Store.TeamProjectCollection
}
else
{
$tpName = "*"
$tpc = Get-TfsTeamProjectCollection $Collection
}
$buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
$query = $buildServer.CreateBuildQueueSpec($tpName, $buildDefName)
$buildServer.QueryQueuedBuilds($query).QueuedBuilds
}
}
<#
.SYNOPSIS
Sets up an additional build service in the current computer
.DESCRIPTION
In Team Foundation Server, the Build Service is a Windows Service that is associated with a particular TFS Team Project Collection (since 2010).
Each Build Service support zero to one (0..1) Build Controllers and zero to n (0..n) Build Agents.
Each Build Agent is associated to a specific Build Controller but an Agent and its corresponding Controller don�t need to be on the same machine.
This topology lets you configure a continuous integration build that queues its builds on the Build Controller you�ve specified which then farms out the heavy lifting to any of the n agents it manages. This gives you an easy way to load balance your builds across a set of machines.
There is a potential down-side, however, in that each build service can only service one particular project collection and you cannot install more than one build service in any given computer.
This script allows you work around that limitation, setting up more than one build service in the same machine.
.NOTES
This is not supported and should not be used in production environments.
#>
Function New-TfsXamlBuildService
{
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$CollectionName,
[Parameter()]
[string]
$BuildServiceName = "TFSBuildServiceHost.2013",
[Parameter()]
[string]
$ComputerName = $env:COMPUTERNAME,
[Parameter()]
[ValidateRange(1,65535)]
[int]
$Port = 9191,
[Parameter(Mandatory=$true)]
[System.Management.Automation.Credential()]
[System.Management.Automation.PSCredential]
$ServiceCredential = (Get-Credential),
[Parameter()]
[switch]
$Force
)
Begin
{
if ($ComputerName -eq "localhost")
{
$ComputerName = $env:COMPUTERNAME
}
$tpc = Get-TfsTeamProjectCollection -Current
$buildServer = $tpc.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")
}
Process
{
$ToolsVersion = 12
$EnvVarName = "TFSBUILDSERVICEHOST.2013"
$BuildEndpointTemplate = "Build/v5.0/Services"
if (-not $TfsInstallationPath)
{
$TfsInstallationPath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\TeamFoundationServer\12.0").InstallPath
}
if (-not $BuildServiceName)
{
$BuildServiceName = "TfsBuildService-$collectionName"
}
$ServiceBinPath = "$TfsInstallationPath\Tools\TfsBuildServiceHost.exe /NamedInstance:$BuildServiceName"
$ServiceDisplayName = "Visual Studio Team Foundation Build Service Host ($collectionName)"
_CreateService $BuildServiceName $ServiceDisplayName $ServiceBinPath $Force.IsPresent
_RegisterBuildServiceHost $TfsInstallationPath $Force.IsPresent
_CreateBuildController
_CreateBuildAgent
}
}
#======================
# Helper methods
#======================
Function _CreateService
{
Param
(
$BuildServiceName,
$ServiceDisplayName,
$ServiceBinPath,
$Force
)
if (Get-Service $BuildServiceName -ErrorAction SilentlyContinue)
{
if (-not $Force)
{
throw "Build Service $BuildServiceName is already registered. To re-register a build service, use the -Force switch"
}
sc.exe delete $BuildServiceName | Out-Null
}
$svc = New-Service -Name $BuildServiceName -DisplayName $ServiceDisplayName -BinaryPathName $ServiceBinPath
sc.exe failure $BuildServiceName reset= 86400 actions= restart/60000 | Out-Null
}
Function _RegisterBuildServiceHost
{
Param
(
$TfsInstallationPath,
$Force
)
_LoadPrivateAssemblies $TfsInstallationPath
$flags = [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::SetProperty -bor [System.Reflection.BindingFlags]::Static
[Microsoft.TeamFoundation.Build.Config.BuildServiceHostProcess].InvokeMember("NamedInstance", $flags, $null, $null, [object[]] $BuildServiceName)
if ($buildServer.QueryBuildServiceHosts($BuildServiceName).Length -ne 0)
{
if (-not $Force)
{
throw "Build Service $BuildServiceName is already registered. To re-register a build service, use the -Force switch"
}
[Microsoft.TeamFoundation.Build.Config.BuildServiceHostUtilities]::Unregister($true, $true)
}
$port = _GetNextAvailablePort
$endpoint = "http://$env:COMPUTERNAME:$port/$BuildEndpointTemplate"
$serviceHost = $buildServer.CreateBuildServiceHost($BuildServiceName, $endpoint)
$serviceHost.Save()
$userName = $ServiceCredential.UserName
$password = $ServiceCredential.GetNetworkCredential().Password
[Microsoft.TeamFoundation.Build.Config.BuildServiceHostUtilities]::Register($serviceHost, $userName, $password)
}
Function _GetNextAvailablePort
{
$RegistryPath = "HKLM:\SOFTWARE\Microsoft\VisualStudio\$ToolsVersion.0\TeamFoundation\Build"
$PortsTaken = Get-ChildItem -Path $RegistryPath | Get-ItemProperty -Name Endpoint | ForEach { [uri] $_.Endpoint } | Select -ExpandProperty Port
$StartPort = 9191
$MaxPorts = $StartPort + $PortsTaken.Length
for ($i = $StartPort; $i -le $MaxPorts; $i++)
{
if ($PortsTaken -notcontains $i)
{
$Port = $i
break
}
}
return $Port
}
Function _LoadPrivateAssemblies
{
Param
(
$TfsInstallationPath
)
$AssemblyPath = "$TfsInstallationPath\Tools\Microsoft.TeamFoundation.Build.Config.dll"
Add-Type -Path $AssemblyPath
}
Function _GetRegValue
{
Param
(
$KeyPath, $ValueName, $ComputerName
)
Process
{
if ((-not $ComputerName) -or ($ComputerName -eq $env:COMPUTERNAME))
{
return Get-ChildItem -Path $KeyPath | Get-ItemProperty -Name $ValueName
}
$KeyMapping = @{
HKCU = "CurrentUser";
HKLM = "LocalMachine"
}
$RootKey = ($KeyPath -split ":\")[0]
$Path = ($KeyPath -split ":\")[1]
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($KeyMapping[$RootKey], $ComputerName)
$RegKey= $Reg.OpenSubKey($Path)
$Value = $RegKey.GetValue($ValueName)
$RegKey.Close()
$Reg.Close()
return $Value
}
}
<#
.SYNOPSIS
Queues a XAML Build.
.PARAMETER BuildDefinition
Build Definition Name that you want to queue.
.PARAMETER Project
Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).
For more details, see the Get-TfsTeamProject cmdlet.
.PARAMETER Collection
Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.
When using a URL, it must be fully qualified. The format of this string is as follows:
http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>
Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.
To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.
For more details, see the Get-TfsTeamProjectCollection cmdlet.
.EXAMPLE
Start-TfsBuild -BuildDefinition "My Build Definition" -Project "MyTeamProject"
This example queue a Build Definition "My Build Definition" of Team Project "MyTeamProject".
#>
Function Start-TfsXamlBuild
{
Param
(
[Parameter(Mandatory=$true, Position=0)]
[object]
$BuildDefinition,
[Parameter(ValueFromPipeline=$true, Mandatory=$true)]
[object]
[ValidateNotNull()]
[ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.WorkItemTracking.Client.Project])})]
$Project,
[Parameter()]
[object]
$Collection,
[Parameter()]
[string]
[ValidateSet("LatestOnQueue", "LatestOnBuild", "Custom")]
$GetOption = "LatestOnBuild",
[Parameter()]
[string]
$GetVersion,
[Parameter()]
[string]
$DropLocation,
[Parameter()]
[hashtable]
$Parameters
)
Process
{
$tp = Get-TfsTeamProject $Project $Collection
$tpc = $tp.Store.TeamProjectCollection
$buildServer = $tpc.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")
if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
{
$buildDef = $BuildDefinition
}
else
{
$buildDef = $buildServer.GetBuildDefinition($tp.Name, $BuildDefinition);
}
$req = $buildDef.CreateBuildRequest()
$req.GetOption = [Microsoft.TeamFoundation.Build.Client.GetOption] $GetOption;
if ($GetOption -eq "Custom")
{
$req.CustomGetVersion = $GetVersion
}
if ($DropLocation)
{
$req.DropLocation = $DropLocation
}
$buildServer.QueueBuild($req)
}
}
Log in or click on link to see number of positives.
- System.IdentityModel.Tokens.Jwt.dll (449b4231dccb) - ## / 68
- System.Net.Http.Formatting.dll (76ea4b2d47bb) - ## / 67
- System.Web.Http.dll (1666e476e653) - ## / 61
- System.Diagnostics.DiagnosticSource.dll (1090bca31222) - ## / 70
- System.Net.Http.dll (94aec4fd3d33) - ## / 56
- System.Security.Cryptography.Encoding.dll (524aa03e14a3) - ## / 71
- System.Security.Cryptography.Primitives.dll (0e3a82c09873) - ## / 73
- TfsCmdlets.1.0.0.894-beta1.nupkg (6d6ae85f20e4) - ## / 59
- Microsoft.IdentityModel.Clients.ActiveDirectory.dll (26bc243d729f) - ## / 62
- Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll (7fd5c5d5f587) - ## / 61
- Microsoft.ServiceBus.dll (a8b01cdbdac5) - ## / 62
- Microsoft.TeamFoundation.Build.Client.dll (9d69766cf302) - ## / 62
- Microsoft.TeamFoundation.Build.Common.dll (7dd91ee375f2) - ## / 61
- Microsoft.TeamFoundation.Build2.WebApi.dll (e6cf3b830e6e) - ## / 71
- Microsoft.TeamFoundation.Chat.WebApi.dll (9bc1963c2591) - ## / 70
- Microsoft.TeamFoundation.Client.dll (54bfb663f843) - ## / 62
- Microsoft.TeamFoundation.Common.dll (55a2c808100d) - ## / 71
- Microsoft.TeamFoundation.Core.WebApi.dll (5019731c050f) - ## / 67
- Microsoft.TeamFoundation.Dashboards.WebApi.dll (edfb834e3ac9) - ## / 71
- Microsoft.TeamFoundation.DeleteTeamProject.dll (78e7ffa1a92a) - ## / 62
- Microsoft.TeamFoundation.Diff.dll (016e83064e18) - ## / 62
- Microsoft.TeamFoundation.Discussion.Client.dll (22e0b259f5a6) - ## / 61
- Microsoft.TeamFoundation.DistributedTask.Common.Contracts.dll (39e4394864c5) - ## / 71
- Microsoft.TeamFoundation.Git.Client.dll (5b9d4281748a) - ## / 61
- Microsoft.TeamFoundation.Lab.Client.dll (bce9e0df26d7) - ## / 62
- Microsoft.TeamFoundation.Lab.Common.dll (e998158c98c8) - ## / 62
- Microsoft.TeamFoundation.Lab.TestIntegration.Client.dll (2bab0fb7d492) - ## / 61
- Microsoft.TeamFoundation.Lab.WorkflowIntegration.Client.dll (1a22d862a846) - ## / 62
- Microsoft.TeamFoundation.Policy.WebApi.dll (73eea8ac56f3) - ## / 71
- Microsoft.TeamFoundation.ProjectManagement.dll (4ea4a391f119) - ## / 62
- Microsoft.TeamFoundation.SharePointReporting.Integration.dll (271b5fd9af4e) - ## / 61
- Microsoft.TeamFoundation.SourceControl.WebApi.dll (4aedd0eaa0b6) - ## / 70
- Microsoft.TeamFoundation.Test.WebApi.dll (46a71879e8b6) - ## / 68
- Microsoft.TeamFoundation.TestImpact.Client.dll (e22fe77e9a92) - ## / 61
- Microsoft.TeamFoundation.TestManagement.Client.dll (62acc521b940) - ## / 62
- Microsoft.TeamFoundation.TestManagement.Common.dll (48f6478543a9) - ## / 60
- Microsoft.TeamFoundation.TestManagement.WebApi.dll (ce100108be01) - ## / 68
- Microsoft.TeamFoundation.VersionControl.Client.dll (7476f7bb89ec) - ## / 60
- Microsoft.TeamFoundation.VersionControl.Common.dll (88b7df735ee0) - ## / 62
- Microsoft.TeamFoundation.VersionControl.Common.Integration.dll (3e3fe48f499d) - ## / 61
- Microsoft.TeamFoundation.Work.WebApi.dll (83005f91e6d3) - ## / 70
- Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll (70a4af6673f0) - ## / 62
- Microsoft.TeamFoundation.WorkItemTracking.Client.dll (c5ca0e0a80c4) - ## / 61
- Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll (f6ebfd09e3ce) - ## / 61
- Microsoft.TeamFoundation.WorkItemTracking.Common.dll (56694941e5c1) - ## / 62
- Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll (45cef3b7030f) - ## / 61
- Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll (28cf4bf8dafa) - ## / 68
- Microsoft.VisualStudio.Services.Client.Interactive.dll (0ca3eb35a853) - ## / 62
- Microsoft.VisualStudio.Services.Common.dll (15dd683880f5) - ## / 72
- Microsoft.VisualStudio.Services.WebApi.dll (818a24d2cb7e) - ## / 71
- Microsoft.Win32.Primitives.dll (7380b517d616) - ## / 54
- Microsoft.WITDataStore32.dll (d6f323ded8c3) - ## / 62
- Microsoft.WITDataStore64.dll (e18f97ab7a54) - ## / 62
- Newtonsoft.Json.dll (820bb4ae31fd) - ## / 68
- System.IO.dll (561cc9016720) - ## / 64
- System.Linq.dll (300ef524f8a9) - ## / 67
- System.Reflection.dll (927e596a90d0) - ## / 70
- System.Runtime.dll (cec22b4f62a4) - ## / 65
- System.Runtime.Extensions.dll (9bc022dae6b2) - ## / 66
- System.Runtime.InteropServices.dll (53e97936af2e) - ## / 56
- System.Runtime.Serialization.Primitives.dll (3aac33ee0485) - ## / 55
- System.Security.Cryptography.Algorithms.dll (24da52cda5c9) - ## / 72
- System.Security.Cryptography.X509Certificates.dll (ce6c6a3d98e7) - ## / 72
- System.Text.RegularExpressions.dll (cd113a5c75cb) - ## / 61
In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).
Chocolatey Pro provides runtime protection from possible malware.
Add to Builder | Version | Downloads | Last Updated | Status |
---|---|---|---|---|
TfsCmdlets 2.9.0 | 40 | Thursday, August 15, 2024 | Approved | |
TfsCmdlets 2.8.2 | 31 | Wednesday, July 24, 2024 | Approved | |
TfsCmdlets 2.8.1 | 25 | Tuesday, July 16, 2024 | Approved | |
TfsCmdlets 2.8.0 | 32 | Tuesday, July 9, 2024 | Approved | |
TfsCmdlets 2.7.1 | 22 | Wednesday, July 3, 2024 | Approved | |
TfsCmdlets 2.6.1 | 42 | Wednesday, May 15, 2024 | Approved | |
TfsCmdlets 2.6.0 | 247 | Saturday, October 1, 2022 | Approved | |
TfsCmdlets 2.5.1 | 61 | Monday, August 22, 2022 | Approved | |
TfsCmdlets 2.5.0 | 59 | Wednesday, August 3, 2022 | Approved | |
TfsCmdlets 2.4.1 | 67 | Thursday, July 21, 2022 | Approved | |
TfsCmdlets 2.4.0 | 89 | Monday, May 23, 2022 | Approved | |
TfsCmdlets 2.3.2 | 61 | Wednesday, May 18, 2022 | Approved | |
TfsCmdlets 2.3.1 | 70 | Saturday, April 9, 2022 | Approved | |
TfsCmdlets 2.3.0 | 67 | Sunday, April 3, 2022 | Approved | |
TfsCmdlets 2.2.1 | 75 | Friday, February 11, 2022 | Approved | |
TfsCmdlets 2.2.0 | 62 | Saturday, February 5, 2022 | Approved | |
TfsCmdlets 2.1.4 | 89 | Tuesday, November 30, 2021 | Approved | |
TfsCmdlets 2.1.3 | 66 | Thursday, November 25, 2021 | Approved | |
TfsCmdlets 2.1.2 | 83 | Friday, September 10, 2021 | Approved | |
TfsCmdlets 2.1.1 | 78 | Wednesday, September 8, 2021 | Approved | |
TfsCmdlets 2.0.0 | 83 | Tuesday, August 3, 2021 | Approved | |
TfsCmdlets 2.0.0-rc0005 | 87 | Sunday, April 18, 2021 | Exempted | |
TfsCmdlets 2.0.0-rc0004 | 87 | Monday, April 5, 2021 | Exempted | |
TfsCmdlets 2.0.0-rc0003 | 74 | Friday, February 19, 2021 | Exempted | |
TfsCmdlets 2.0.0-rc0002 | 84 | Tuesday, December 1, 2020 | Exempted | |
TfsCmdlets 2.0.0-beta0015 | 84 | Tuesday, July 21, 2020 | Exempted | |
TfsCmdlets 2.0.0-beta0014 | 65 | Sunday, July 19, 2020 | Exempted | |
TfsCmdlets 2.0.0-beta0013 | 67 | Saturday, July 18, 2020 | Exempted | |
TfsCmdlets 2.0.0-beta0010 | 157 | Thursday, September 12, 2019 | Exempted | |
TfsCmdlets 2.0.0-beta0009 | 93 | Tuesday, September 10, 2019 | Exempted | |
TfsCmdlets 2.0.0-beta0008 | 103 | Friday, September 6, 2019 | Exempted | |
TfsCmdlets 2.0.0-beta0004 | 117 | Thursday, August 29, 2019 | Exempted | |
TfsCmdlets 1.0.0.894-beta1 | 389 | Thursday, April 6, 2017 | Exempted | |
TfsCmdlets 1.0.0-alpha9 | 332 | Saturday, December 24, 2016 | Exempted | |
TfsCmdlets 1.0.0-alpha7 | 299 | Thursday, October 22, 2015 | Exempted | |
TfsCmdlets 1.0.0-alpha6 | 279 | Thursday, October 22, 2015 | Exempted | |
TfsCmdlets 1.0.0-alpha5 | 255 | Thursday, September 10, 2015 | Exempted | |
TfsCmdlets 1.0.0-alpha4 | 247 | Friday, September 4, 2015 | Exempted | |
TfsCmdlets 1.0.0-alpha3 | 311 | Thursday, September 3, 2015 | Exempted | |
TfsCmdlets 1.0.0-alpha1 | 310 | Friday, July 31, 2015 | Exempted |
(c) 2014 Igor Abade V. Leite. All rights reserved.
This package has no dependencies.
Ground Rules:
- This discussion is only about TfsCmdlets and the TfsCmdlets package. If you have feedback for Chocolatey, please contact the Google Group.
- This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
- The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
- Tell us what you love about the package or TfsCmdlets, or tell us what needs improvement.
- Share your experiences with the package, or extra configuration or gotchas that you've found.
- If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.