diff --git a/.docs/Remove-VSTeamWorkItem.md b/.docs/Remove-VSTeamWorkItem.md
new file mode 100644
index 000000000..caa013a9e
--- /dev/null
+++ b/.docs/Remove-VSTeamWorkItem.md
@@ -0,0 +1,85 @@
+
+
+# Remove-VSTeamWorkItem
+
+## SYNOPSIS
+
+
+
+## SYNTAX
+
+## DESCRIPTION
+
+
+
+## EXAMPLES
+
+### -------------------------- EXAMPLE 1 --------------------------
+
+```PowerShell
+PS C:\> Remove-VSTeamWorkItem -Ids 47,48
+```
+
+This command deletes work items with IDs 47 and 48 by using the IDs parameter.
+
+### -------------------------- EXAMPLE 2 --------------------------
+
+```PowerShell
+PS C:\> Remove-VSTeamWorkItem -Id 47
+```
+
+This command deletes the work item with ID 47 by using the ID parameter.
+
+### -------------------------- EXAMPLE 3 --------------------------
+
+```PowerShell
+PS C:\> Remove-VSTeamWorkItem -Ids 47 -Destroy
+```
+
+This command deletes work item with IDs 47 **permanently** by using the Destroy parameter.
+
+## PARAMETERS
+
+### -Id
+
+The id of the work item.
+
+```yaml
+Type: Int32
+Parameter Sets: ByID
+Required: True
+Accept pipeline input: true (ByPropertyName, ByValue)
+```
+
+### -Ids
+
+The id of the work item.
+
+```yaml
+Type: Int32[]
+Parameter Sets: List
+Required: True
+Accept pipeline input: true (ByPropertyName, ByValue)
+```
+
+### -Destroy
+
+Optional parameter, if set to true, the work item is deleted permanently. **Please note: the destroy action is PERMANENT and cannot be undone.**
+
+```yaml
+Type: Switch
+```
+
+## INPUTS
+
+### System.String
+
+ProjectName
+
+## OUTPUTS
+
+## NOTES
+
+If you do not set the default project by called Set-VSTeamDefaultProject before calling Get-VSTeamWorkItem you will have to type in the names.
+
+## RELATED LINKS
diff --git a/.docs/synopsis/Remove-VSTeamWorkItem.md b/.docs/synopsis/Remove-VSTeamWorkItem.md
new file mode 100644
index 000000000..988f2c6da
--- /dev/null
+++ b/.docs/synopsis/Remove-VSTeamWorkItem.md
@@ -0,0 +1 @@
+Deletes the specified work item and sends it to the Recycle Bin, so that it can be restored back, if required. Optionally, if the destroy parameter has been set to true, it destroys the work item permanently. WARNING: If the destroy parameter is set to true, work items deleted by this command will NOT go to recycle-bin and there is no way to restore/recover them after deletion. It is recommended NOT to use this parameter. If you do, please use this parameter with extreme caution.
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b11fce5c..cdcf9d65c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## 6.4.0
+Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/209) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:
+
+Added Remove-VSTeamWorkItem to delete work items
+
Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/204) from [Jeroen Janssen](https://github.com/japj) which included the following:
add maxParallelism to Disable/Enable-VSTeamAgent
diff --git a/Source/Private/applyTypes.ps1 b/Source/Private/applyTypes.ps1
index 8e55440f5..85015dce3 100644
--- a/Source/Private/applyTypes.ps1
+++ b/Source/Private/applyTypes.ps1
@@ -25,6 +25,12 @@ function _applyTypesToWorkItem {
}
}
+function _applyTypesToWorkItemDeleted {
+ param($item)
+ $item.PSObject.TypeNames.Insert(0, 'Team.WorkItemDeleted')
+ $item.resource.PSObject.TypeNames.Insert(0,'Team.WorkItem')
+}
+
function _applyTypesToWiql {
param($item)
if ($item) {
diff --git a/Source/Public/Remove-VSTeamWorkItem.ps1 b/Source/Public/Remove-VSTeamWorkItem.ps1
new file mode 100644
index 000000000..922d2d1d6
--- /dev/null
+++ b/Source/Public/Remove-VSTeamWorkItem.ps1
@@ -0,0 +1,50 @@
+function Remove-VSTeamWorkItem {
+ [CmdletBinding(DefaultParameterSetName = 'ByID')]
+ param(
+ [Parameter(ParameterSetName = 'ByID', Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
+ [int] $Id,
+
+ [Parameter(ParameterSetName = 'List', Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
+ [int[]] $Ids,
+
+ [switch] $Destroy
+ )
+
+ Process {
+ # Call the REST API
+
+ $idsToDelete = @()
+
+ if ($PSCmdlet.ParameterSetName -eq "List") {
+
+ if($null -eq $Ids) {
+ throw "No Ids given, array was null"
+ }
+
+ $idsToDelete = $Ids
+ }
+ else {
+
+ # work item IDs in AzD cannot be lower than 1. First work item id is always 1.
+ if($Id -lt 1) {
+ throw "given work item Id has to be greater than 0"
+ }
+
+ $idsToDelete = @($id[0])
+ }
+
+ $deletedWorkItems = foreach ($wiId in $idsToDelete) {
+ $resp = _callAPI -Method "DELETE" -Area 'wit' -Resource 'workitems' `
+ -Version $([VSTeamVersions]::Core) -id "$wiId" `
+ -Querystring @{
+ destroy = $Destroy
+ }
+
+ _applyTypesToWorkItemDeleted -item $resp
+
+ $resp
+ }
+
+ return $deletedWorkItems
+ }
+}
\ No newline at end of file
diff --git a/Source/formats/Team.WorkItemDeleted.ListView.ps1xml b/Source/formats/Team.WorkItemDeleted.ListView.ps1xml
new file mode 100644
index 000000000..a21e0c9d3
--- /dev/null
+++ b/Source/formats/Team.WorkItemDeleted.ListView.ps1xml
@@ -0,0 +1,34 @@
+
+
+
+
+ Team.WorkItemDeleted.ListView
+
+ Team.WorkItemDeleted
+
+
+
+
+
+
+ id
+
+
+ name
+
+
+ deletedBy
+
+
+ deletedDate
+
+
+ code
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/formats/Team.WorkItemDeleted.TableView.ps1xml b/Source/formats/Team.WorkItemDeleted.TableView.ps1xml
new file mode 100644
index 000000000..16b92770a
--- /dev/null
+++ b/Source/formats/Team.WorkItemDeleted.TableView.ps1xml
@@ -0,0 +1,51 @@
+
+
+
+
+ Team.WorkItemDeleted.TableView
+
+ Team.WorkItemDeleted
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+
+
+ name
+
+
+ deletedBy
+
+
+ deletedDate
+
+
+ code
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/formats/_formats.json b/Source/formats/_formats.json
index c965e5393..f4f6ff1eb 100644
--- a/Source/formats/_formats.json
+++ b/Source/formats/_formats.json
@@ -93,6 +93,8 @@
"Team.Wiql.ListView.ps1xml",
"Team.WorkItem.TableView.ps1xml",
"Team.WorkItem.ListView.ps1xml",
+ "Team.WorkItemDeleted.TableView.ps1xml",
+ "Team.WorkItemDeleted.ListView.ps1xml",
"Team.JobRequest.TableView.ps1xml"
]
}
\ No newline at end of file
diff --git a/Source/types/Team.WorkItemDeleted.ps1xml b/Source/types/Team.WorkItemDeleted.ps1xml
new file mode 100644
index 000000000..17254712a
--- /dev/null
+++ b/Source/types/Team.WorkItemDeleted.ps1xml
@@ -0,0 +1,59 @@
+
+
+
+ Team.WorkItemDeleted
+
+
+ Name
+ $this.fields.PSObject.Properties['name'].Value
+
+
+ Project
+ $this.fields.PSObject.Properties['project'].Value
+
+
+ Type
+ $this.fields.PSObject.Properties['type'].Value
+
+
+ Id
+ $this.fields.PSObject.Properties['id'].Value
+
+
+ Resource
+ $this.fields.PSObject.Properties['resource'].Value
+
+
+ DeletedBy
+ $this.fields.PSObject.Properties['deletedBy'].Value
+
+
+ DeletedDate
+ $this.fields.PSObject.Properties['deletedDate'].Value
+
+
+ Code
+ $this.fields.PSObject.Properties['code'].Value
+
+
+ Url
+ $this.fields.PSObject.Properties['url'].Value
+
+
+ PSStandardMembers
+
+
+ DefaultDisplayPropertySet
+
+ id
+ name
+ deletedBy
+ deletedDate
+ code
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/unit/test/wiql.Tests.ps1 b/unit/test/wiql.Tests.ps1
index 53f8be35f..bc9543019 100644
--- a/unit/test/wiql.Tests.ps1
+++ b/unit/test/wiql.Tests.ps1
@@ -33,12 +33,12 @@ InModuleScope VSTeam {
asOf = "2019-10-03T18:35:09.117Z"
columns = @($column)
sortColumns = @($sortColumn)
- workItems = @($workItem, $workItem)
+ workItems = @($workItem, $workItem)
}
$expandedWorkItems = @{
count = 1
- value = @($workItem, $workItem)
+ value = @($workItem, $workItem)
}
Context 'Get-Wiql' {
diff --git a/unit/test/workitem.Tests.ps1 b/unit/test/workitem.Tests.ps1
index a344f23d4..e00874637 100644
--- a/unit/test/workitem.Tests.ps1
+++ b/unit/test/workitem.Tests.ps1
@@ -15,13 +15,26 @@ InModuleScope VSTeam {
id = 47
rev = 1
url = "https://dev.azure.com/test/_apis/wit/workItems/47"
- }
+ }
$collection = @{
count = 1
value = @($obj)
}
+ $objDeleted = @{
+ id = 47
+ name = "Test Work Item 47"
+ deletedBy = "Theobald Test "
+ deletedDate = "10/19/2019 9:08:48 PM"
+ code = 200
+ resource = $obj
+ }
+
+ $collectionDeleted = @(
+ $objDeleted
+ )
+
Context 'Add-WorkItem' {
Mock Invoke-RestMethod {
# If this test fails uncomment the line below to see how the mock was called.
@@ -284,5 +297,68 @@ InModuleScope VSTeam {
}
}
}
+
+ Context 'Remove-WorkItem'{
+
+ It 'Should delete single work item' {
+ Mock Invoke-RestMethod {
+ # If this test fails uncomment the line below to see how the mock was called.
+ #Write-Host $args
+
+ return $collectionDeleted
+ }
+
+ Remove-VSTeamWorkItem -Id 47
+
+ Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter {
+ $Uri -like "*https://dev.azure.com/test/_apis/wit/workitems/*" -and
+ $Uri -like "*api-version=$([VSTeamVersions]::Core)*" -and
+ $Uri -like "*workitems/47*"
+ }
+ }
+
+ It 'Should throw single work item with id equals $null' {
+ {Remove-VSTeamWorkItem -Id $null} | Should -Throw
+ }
+
+ It 'Should delete multipe work items' {
+ Mock Invoke-RestMethod {
+ # If this test fails uncomment the line below to see how the mock was called.
+ #Write-Host $args
+
+ return $collectionDeleted
+ }
+
+ Remove-VSTeamWorkItem -Ids 47, 48
+
+ Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 2 -ParameterFilter {
+ $Uri -like "*https://dev.azure.com/test/_apis/wit/workitems/*" -and
+ $Uri -like "*api-version=$([VSTeamVersions]::Core)*" -and
+ ($Uri -like "*workitems/47*" -or $Uri -like "*workitems/48*")
+ }
+ }
+
+ It 'Single Work Item Should be deleted permanently' {
+ Mock Invoke-RestMethod {
+ # If this test fails uncomment the line below to see how the mock was called.
+ #Write-Host $args
+
+ return $collectionDeleted
+ }
+
+ Remove-VSTeamWorkItem -Ids 47, 48 -Destroy
+
+ Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 2 -ParameterFilter {
+ $Uri -like "*https://dev.azure.com/test/_apis/wit/workitems/*" -and
+ $Uri -like "*api-version=$([VSTeamVersions]::Core)*" -and
+ ($Uri -like "*workitems/47*" -or $Uri -like "*workitems/48*") -and
+ $Uri -like "*destroy=True*"
+ }
+ }
+
+ It 'Should throw multiple work item with array equals $null' {
+ {Remove-VSTeamWorkItem -Ids $null} | Should -Throw
+ }
+ }
}
}
\ No newline at end of file