diff --git a/.docs/Disable-VSTeamAgent.md b/.docs/Disable-VSTeamAgent.md
new file mode 100644
index 000000000..1177b8197
--- /dev/null
+++ b/.docs/Disable-VSTeamAgent.md
@@ -0,0 +1,48 @@
+
+
+# Disable-VSTeamAgent
+
+## SYNOPSIS
+
+
+
+## SYNTAX
+
+## DESCRIPTION
+
+
+
+## EXAMPLES
+
+## PARAMETERS
+
+### -PoolId
+
+Id of the pool.
+
+```yaml
+Type: int
+Required: True
+Accept pipeline input: true (ByValue)
+```
+
+### -Id
+
+Id of the agent to disable.
+
+```yaml
+Type: int[]
+Aliases: AgentID
+Required: True
+Accept pipeline input: true (ByPropertyName)
+```
+
+## INPUTS
+
+### System.String
+
+## OUTPUTS
+
+## NOTES
+
+## RELATED LINKS
\ No newline at end of file
diff --git a/.docs/Enable-VSTeamAgent.md b/.docs/Enable-VSTeamAgent.md
new file mode 100644
index 000000000..ffe91b343
--- /dev/null
+++ b/.docs/Enable-VSTeamAgent.md
@@ -0,0 +1,48 @@
+
+
+# Enable-VSTeamAgent
+
+## SYNOPSIS
+
+
+
+## SYNTAX
+
+## DESCRIPTION
+
+
+
+## EXAMPLES
+
+## PARAMETERS
+
+### -PoolId
+
+Id of the pool.
+
+```yaml
+Type: int
+Required: True
+Accept pipeline input: true (ByValue)
+```
+
+### -Id
+
+Id of the agent to enable.
+
+```yaml
+Type: int[]
+Aliases: AgentID
+Required: True
+Accept pipeline input: true (ByPropertyName)
+```
+
+## INPUTS
+
+### System.String
+
+## OUTPUTS
+
+## NOTES
+
+## RELATED LINKS
\ No newline at end of file
diff --git a/.docs/Get-VSTeamPool.md b/.docs/Get-VSTeamPool.md
index 54bd9d882..d4374aa09 100644
--- a/.docs/Get-VSTeamPool.md
+++ b/.docs/Get-VSTeamPool.md
@@ -21,7 +21,7 @@
Id of the pool to return.
```yaml
-Type: String
+Type: int
Parameter Sets: ByID
Aliases: PoolID
Required: True
diff --git a/.docs/Remove-VSTeamAgent.md b/.docs/Remove-VSTeamAgent.md
index 93e9f8375..8220224da 100644
--- a/.docs/Remove-VSTeamAgent.md
+++ b/.docs/Remove-VSTeamAgent.md
@@ -21,7 +21,7 @@
Id of the pool.
```yaml
-Type: String
+Type: int
Required: True
Accept pipeline input: true (ByValue)
```
@@ -31,7 +31,7 @@ Accept pipeline input: true (ByValue)
Id of the agent to remove.
```yaml
-Type: int
+Type: int[]
Aliases: AgentID
Required: True
Accept pipeline input: true (ByPropertyName)
diff --git a/.docs/synopsis/Disable-VSTeamAgent.md b/.docs/synopsis/Disable-VSTeamAgent.md
new file mode 100644
index 000000000..397d64682
--- /dev/null
+++ b/.docs/synopsis/Disable-VSTeamAgent.md
@@ -0,0 +1 @@
+Disables an agent in a pool.
\ No newline at end of file
diff --git a/.docs/synopsis/Enable-VSTeamAgent.md b/.docs/synopsis/Enable-VSTeamAgent.md
new file mode 100644
index 000000000..e21dbd2bc
--- /dev/null
+++ b/.docs/synopsis/Enable-VSTeamAgent.md
@@ -0,0 +1 @@
+Enables an agent in a pool.
\ No newline at end of file
diff --git a/VSTeam.psd1 b/VSTeam.psd1
index 8c0343c1c..b0573c40b 100644
--- a/VSTeam.psd1
+++ b/VSTeam.psd1
@@ -203,7 +203,9 @@
'Show-VSTeamWorkItem',
'Get-VSTeamGitRef',
'Get-VSTeamAgent',
- 'Remove-VSTeamAgent')
+ 'Remove-VSTeamAgent',
+ 'Enable-VSTeamAgent',
+ 'Disable-VSTeamAgent')
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
# CmdletsToExport = @()
@@ -304,7 +306,9 @@
'Remove-Policy',
'Get-GitRef',
'Get-Agent',
- 'Remove-Agent')
+ 'Remove-Agent',
+ 'Enable-Agent',
+ 'Disable-Agent')
# DSC resources to export from this module
# DscResourcesToExport = @()
diff --git a/docs/Get-VSTeamPool.md b/docs/Get-VSTeamPool.md
index 969efdfc1..a7047ae76 100644
--- a/docs/Get-VSTeamPool.md
+++ b/docs/Get-VSTeamPool.md
@@ -22,7 +22,7 @@ Returns the agent pools.
Id of the pool to return.
```yaml
-Type: String
+Type: int
Parameter Sets: ByID
Aliases: PoolID
Required: True
diff --git a/docs/Team.md b/docs/Team.md
index ea3438899..7b787e990 100644
--- a/docs/Team.md
+++ b/docs/Team.md
@@ -91,6 +91,14 @@ Adds a work item to your project.
Clears the value stored in the default project parameter value.
+### [Disable-VSTeamAgent](Disable-VSTeamAgent.md)
+
+Disables an agent in a pool.
+
+### [Enable-VSTeamAgent](Enable-VSTeamAgent.md)
+
+Enables an agent in a pool.
+
### [Get-VSTeam](Get-VSTeam.md)
Returns a team.
diff --git a/docs/readme.md b/docs/readme.md
index d585844fb..bf1fe0217 100644
--- a/docs/readme.md
+++ b/docs/readme.md
@@ -96,6 +96,14 @@ Adds a work item to your project.
Clears the value stored in the default project parameter value.
+### [Disable-VSTeamAgent](Disable-VSTeamAgent.md)
+
+Disables an agent in a pool.
+
+### [Enable-VSTeamAgent](Enable-VSTeamAgent.md)
+
+Enables an agent in a pool.
+
### [Get-VSTeam](Get-VSTeam.md)
Returns a team.
diff --git a/en-US/VSTeam-Help.xml b/en-US/VSTeam-Help.xml
index 05580e813..f77535619 100644
--- a/en-US/VSTeam-Help.xml
+++ b/en-US/VSTeam-Help.xml
@@ -3967,6 +3967,178 @@ Demo-CI Demo-CI-45 notStarted
+
+
+ Disable-VSTeamAgent
+ Disable
+ VSTeamAgent
+
+ Disables an agent in a pool.
+
+
+
+ Disables an agent in a pool.
+
+
+
+ Disable-VSTeamAgent
+
+ PoolId
+
+ Id of the pool.
+
+ int
+
+ int
+
+
+ None
+
+
+ Id
+
+ Id of the agent to disable.
+
+ int[]
+
+ int[]
+
+
+ None
+
+
+
+
+
+ PoolId
+
+ Id of the pool.
+
+ int
+
+ int
+
+
+ None
+
+
+ Id
+
+ Id of the agent to disable.
+
+ int[]
+
+ int[]
+
+
+ None
+
+
+
+
+
+ System.String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enable-VSTeamAgent
+ Enable
+ VSTeamAgent
+
+ Enables an agent in a pool.
+
+
+
+ Enables an agent in a pool.
+
+
+
+ Enable-VSTeamAgent
+
+ PoolId
+
+ Id of the pool.
+
+ int
+
+ int
+
+
+ None
+
+
+ Id
+
+ Id of the agent to enable.
+
+ int[]
+
+ int[]
+
+
+ None
+
+
+
+
+
+ PoolId
+
+ Id of the pool.
+
+ int
+
+ int
+
+
+ None
+
+
+ Id
+
+ Id of the agent to enable.
+
+ int[]
+
+ int[]
+
+
+ None
+
+
+
+
+
+ System.String
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Get-VSTeam
@@ -6159,9 +6331,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the pool to return.
- String
+ int
- String
+ int
None
@@ -6174,9 +6346,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the pool to return.
- String
+ int
- String
+ int
None
@@ -8880,9 +9052,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the pool.
- String
+ int
- String
+ int
None
@@ -8892,9 +9064,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the agent to remove.
- int
+ int[]
- int
+ int[]
None
@@ -8918,9 +9090,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the pool.
- String
+ int
- String
+ int
None
@@ -8930,9 +9102,9 @@ Demo-CI Demo-CI-45 notStarted
Id of the agent to remove.
- int
+ int[]
- int
+ int[]
None
diff --git a/formats/vsteamPSDrive.format.ps1xml b/formats/vsteamPSDrive.format.ps1xml
index f040a6d3f..571910472 100644
--- a/formats/vsteamPSDrive.format.ps1xml
+++ b/formats/vsteamPSDrive.format.ps1xml
@@ -91,6 +91,9 @@
+
+
+
@@ -108,6 +111,9 @@
name
+
+ enabled
+
version
@@ -138,6 +144,9 @@
+
+
+
@@ -155,6 +164,9 @@
name
+
+ enabled
+
version
diff --git a/src/agents.psm1 b/src/agents.psm1
index 636e9f79a..fe6bb0cd4 100644
--- a/src/agents.psm1
+++ b/src/agents.psm1
@@ -12,7 +12,7 @@ function Get-VSTeamAgent {
[Parameter(ParameterSetName = 'ByID', Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
[Alias('AgentID')]
- [string] $Id
+ [int] $Id
)
process {
@@ -72,9 +72,57 @@ function Remove-VSTeamAgent {
}
}
+function Enable-VSTeamAgent {
+ param(
+ [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
+ [int] $PoolId,
+
+ [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
+ [Alias('AgentID')]
+ [int[]] $Id
+ )
+
+ process {
+ foreach ($item in $Id) {
+ try {
+ _callAPI -Method Patch -Area "distributedtask/pools/$PoolId" -Resource agents -Id $item -Version $VSTeamVersionTable.DistributedTask -ContentType "application/json" -Body "{'enabled':true,'id':$item}" | Out-Null
+ Write-Output "Enabled agent $item"
+ }
+ catch {
+ _handleException $_
+ }
+ }
+ }
+}
+
+function Disable-VSTeamAgent {
+ param(
+ [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
+ [int] $PoolId,
+
+ [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
+ [Alias('AgentID')]
+ [int[]] $Id
+ )
+
+ process {
+ foreach ($item in $Id) {
+ try {
+ _callAPI -Method Patch -Area "distributedtask/pools/$PoolId" -Resource agents -Id $item -Version $VSTeamVersionTable.DistributedTask -ContentType "application/json" -Body "{'enabled':false,'id':$item}" | Out-Null
+ Write-Output "Disabled agent $item"
+ }
+ catch {
+ _handleException $_
+ }
+ }
+ }
+}
+
Set-Alias Get-Agent Get-VSTeamAgent
Set-Alias Remove-Agent Remove-VSTeamAgent
+Set-Alias Enable-Agent Enable-VSTeamAgent
+Set-Alias Disable-Agent Disable-VSTeamAgent
Export-ModuleMember `
- -Function Get-VSTeamAgent, Remove-VSTeamAgent `
- -Alias Get-Agent, Remove-Agent
\ No newline at end of file
+ -Function Get-VSTeamAgent, Remove-VSTeamAgent, Enable-VSTeamAgent, Disable-VSTeamAgent `
+ -Alias Get-Agent, Remove-Agent, Enable-Agent, Disable-Agent
\ No newline at end of file
diff --git a/src/pools.psm1 b/src/pools.psm1
index d68c71230..43027fd9b 100644
--- a/src/pools.psm1
+++ b/src/pools.psm1
@@ -9,7 +9,7 @@ function Get-VSTeamPool {
param(
[Parameter(ParameterSetName = 'ByID', Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
[Alias('PoolID')]
- [string] $Id
+ [int] $Id
)
process {
diff --git a/src/teamspsdrive.ps1 b/src/teamspsdrive.ps1
index e79bd279e..ff3d5c49b 100644
--- a/src/teamspsdrive.ps1
+++ b/src/teamspsdrive.ps1
@@ -324,6 +324,7 @@ class VSTeamAgent : VSTeamLeaf {
[string]$version
[string]$status
[string]$os
+ [bool]$enabled
[PSCustomObject]$systemCapabilities
VSTeamAgent (
@@ -331,6 +332,7 @@ class VSTeamAgent : VSTeamLeaf {
) : base($obj.name, $obj.Id, $null) {
$this.status = $obj.status
+ $this.enabled = $obj.enabled
$this.version = $obj.version
$this.systemCapabilities = $obj.systemCapabilities
diff --git a/unit/test/agents.Tests.ps1 b/unit/test/agents.Tests.ps1
index 3c4c9d048..3127af412 100644
--- a/unit/test/agents.Tests.ps1
+++ b/unit/test/agents.Tests.ps1
@@ -11,6 +11,7 @@ InModuleScope agents {
id = 102
status = 'Online'
version = '1.336.1'
+ enabled = $true
osDescription = 'Linux'
name = 'Test_Agent'
authorization = [PSCustomObject]@{}
@@ -87,5 +88,47 @@ InModuleScope agents {
{ Remove-VSTeamAgent -Pool 36 -Id 950 -Force } | Should Throw
}
}
+
+ Context 'Enable-VSTeamAgent by ID' {
+ Mock Invoke-RestMethod
+
+ It 'should enable the agent with passed in Id' {
+ Enable-VSTeamAgent -Pool 36 -Id 950
+
+ Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
+ $Method -eq 'Patch' -and
+ $Uri -eq "https://test.visualstudio.com/_apis/distributedtask/pools/36/agents/950?api-version=$($VSTeamVersionTable.DistributedTask)"
+ }
+ }
+ }
+
+ Context 'Enable-VSTeamAgent throws' {
+ Mock Invoke-RestMethod { throw 'boom' }
+
+ It 'should enable the agent with passed in Id' {
+ { Enable-VSTeamAgent -Pool 36 -Id 950 } | Should Throw
+ }
+ }
+
+ Context 'Disable-VSTeamAgent by ID' {
+ Mock Invoke-RestMethod
+
+ It 'should disable the agent with passed in Id' {
+ Disable-VSTeamAgent -Pool 36 -Id 950
+
+ Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
+ $Method -eq 'Patch' -and
+ $Uri -eq "https://test.visualstudio.com/_apis/distributedtask/pools/36/agents/950?api-version=$($VSTeamVersionTable.DistributedTask)"
+ }
+ }
+ }
+
+ Context 'Disable-VSTeamAgent throws' {
+ Mock Invoke-RestMethod { throw 'boom' }
+
+ It 'should disable the agent with passed in Id' {
+ { Disable-VSTeamAgent -Pool 36 -Id 950 } | Should Throw
+ }
+ }
}
}
\ No newline at end of file
diff --git a/unit/test/teamspsdrive.Tests.ps1 b/unit/test/teamspsdrive.Tests.ps1
index 037072074..c8796a38f 100644
--- a/unit/test/teamspsdrive.Tests.ps1
+++ b/unit/test/teamspsdrive.Tests.ps1
@@ -119,6 +119,7 @@ Describe 'TeamsPSDrive' {
createdOn = '2018-03-28T16:48:58.317Z'
maxParallelism = 1
id = 102
+ enabled = $false
status = 'Online'
version = '1.336.1'
osDescription = 'Linux'