-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: Command to add a template to an adb item
- Loading branch information
1 parent
d5f8e4d
commit 0a9a670
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<# | ||
.SYNOPSIS | ||
Add the template name to a the adb item. | ||
.DESCRIPTION | ||
This command will query all existing templates on the adb item, merge | ||
them with the spcified template name and then update the new template | ||
list. | ||
.INPUTS | ||
None | ||
.OUTPUTS | ||
None | ||
.EXAMPLE | ||
PS C:\> Add-AdmItemTemplate -Name 'myname' -Template 'mytpl' | ||
Add the template mytpl to the item myname. | ||
#> | ||
function Add-AdbItemTemplate | ||
{ | ||
[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 template to add to the item. | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$Template | ||
) | ||
|
||
$Session = Test-AdbSession -Session $Session | ||
|
||
$item = Get-AdbItem -Session $Session -Name $Name | ||
|
||
# Prepare the template list | ||
$templates = [System.String[]] $item.templatesNames | ||
$templates += $Template | ||
$templates = $templates | Select-Object -Unique | Sort-Object | ||
|
||
$item = [PSCustomObject] @{ | ||
name = $Name | ||
templatesNames = $templates | ||
} | ||
|
||
$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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters