Skip to content

Commit

Permalink
Added: Command to add a parent to an adb item
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiospizzi committed Apr 9, 2020
1 parent 0a9a670 commit 8251f14
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions Adb/Adb.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
'Set-AdbItemProperty'
'Remove-AdbItemProperty'
'Add-AdbItemTemplate'
'Add-AdbItemParent'
# Item Validation
'Test-AdbItemValidation'
)
Expand Down
63 changes: 63 additions & 0 deletions Adb/Functions/Add-AdbItemParent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<#
.SYNOPSIS
Add the parent item to the adb item.
.DESCRIPTION
...
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
PS C:\> Add-AdbItemParent -Name 'myname' -Parent 'myparent'
Add the parent myparent to the item myname.
#>
function Add-AdbItemParent
{
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
# The adb session.
[Parameter(Mandatory = $false)]
[PSTypeName('Adb.Session')]
[System.Object]
$Session,

# The item name.
[Parameter(Mandatory = $true)]
[System.String]
$Name,

# The parent to add to the item.
[Parameter(Mandatory = $true)]
[System.String]
$Parent
)

$Session = Test-AdbSession -Session $Session

$item = Get-AdbItem -Session $Session -Name $Name

# Prepare the parent list
$parents = [System.String[]] $item.parentsNames
$parents += $Parent
$parents = $parents | Select-Object -Unique | Sort-Object

$item = [PSCustomObject] @{
name = $Name
parentsNames = $parents
}

$requestSplat = Get-AdbSessionRequestSplat -Session $Session -Method 'Put'
$requestSplat['Uri'] = '{0}/items/{1}' -f $Session.Uri, $Name
$requestSplat['Body'] = $item | ConvertTo-Json -Compress -Depth 99

if ($PSCmdlet.ShouldProcess($requestSplat.Uri, $requestSplat.Method.ToUpper()))
{
Write-Verbose ('{0} {1} {2}' -f $requestSplat.Method.ToUpper(), $requestSplat.Uri, $requestSplat.Body)
Invoke-RestMethod @requestSplat -Verbose:$false -ErrorAction 'Stop' | Out-Null
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

* Added: Command to add a template to an adb item
* Added: Command to add a parent to an adb item

## 1.3.0 - 2020-04-08

Expand Down

0 comments on commit 8251f14

Please sign in to comment.