Last active
January 8, 2024 19:05
-
-
Save joshooaj/da8d809f5f57ed6e6be5d5829baa1656 to your computer and use it in GitHub Desktop.
Get MIPKind and MIPItem objects using Configuration API commands in MilestonePSTools
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
function Get-MipKind { | |
<# | |
.SYNOPSIS | |
Gets all matching Milestone Integration Platform types or "Kinds". | |
.DESCRIPTION | |
The `Get-MipKind` cmdlet gets all matching Milestone Integration Platform | |
types or "Kinds". The term "Kind" in MIP integrations represents a type of | |
configuration object. Cameras for example have a "Kind" with the ID | |
'5135ba21-f1dc-4321-806a-6ce2017343c0', and both first and third party | |
integrations can expose new types or "kinds" of configuration items. | |
New item "kinds" introduced through a server-side MIP plugin may be found | |
under the "/MIPKindFolder" configuration api path. Each MIPKindFolder may | |
contain one or more MIPItems. | |
.PARAMETER Name | |
Specifies the display name of the MIPKind to be returned, with support for wildcards. The default behavior is to return all MIPKinds. | |
.PARAMETER LiteralName | |
Specifies the literal display name of the MIPKind to be returned. | |
.EXAMPLE | |
Get-MipKind | |
Get all available MIPKinds under the /MIPKindFolder configuration item path. | |
.EXAMPLE | |
Get-MipKind -Name *incident* | |
Get all MIPKinds available with 'incident' in the display name for the MIPKind. | |
.EXAMPLE | |
Get-MipKind *incident* | |
Get all MIPKinds available with 'incident' in the display name for the MIPKind using the positional parameter 'Name'. | |
.EXAMPLE | |
Get-MipKind -LiteralName 'Mobile Servers' | |
Get the MIPKind representing Milestone Mobile Servers. | |
.EXAMPLE | |
Get-MipKind -LiteralName 'Mobile Servers' | Get-MipItem | |
Get the MIPItems representing all configured Milestone Mobile Servers. | |
#> | |
[CmdletBinding(DefaultParameterSetName = 'Name')] | |
[OutputType([VideoOS.ConfigurationApi.ClientService.ConfigurationItem])] | |
param ( | |
[Parameter(ParameterSetName = 'Name', Position = 0)] | |
[string] | |
$Name = '*', | |
[Parameter(ParameterSetName = 'LiteralName')] | |
[string] | |
$LiteralName | |
) | |
process { | |
$matchFound = $false | |
foreach ($item in Get-ConfigurationItem '/MIPKindFolder' -ChildItems) { | |
switch ($PSCmdlet.ParameterSetName) { | |
'Name' { | |
$pattern = [system.management.automation.wildcardpattern]::new($Name, [system.management.automation.wildcardoptions]::IgnoreCase) | |
if ($pattern.IsMatch($item.DisplayName)) { | |
$matchFound = $true | |
$item | |
} | |
} | |
'LiteralName' { | |
if ($item.DisplayName -eq $LiteralName) { | |
$matchFound = $true | |
$item | |
} | |
} | |
Default { | |
throw "ParameterSetName $_ not implemented." | |
} | |
} | |
} | |
if (-not $matchFound -and ($PSCmdlet.ParameterSetName -eq 'LiteralName' -or -not [wildcardpattern]::ContainsWildcardCharacters($Name))) { | |
if (-not [string]::IsNullOrEmpty($LiteralName)) { | |
$Name = $LiteralName | |
} | |
Write-Error "No item found with a display name matching '$Name'" | |
} | |
} | |
} | |
function Get-MipItem { | |
<# | |
.SYNOPSIS | |
Gets all MIPItems of the specified Kind. | |
.DESCRIPTION | |
The `Get-MipItem` cmdlet gets all MIPItems of the specified MIPKind. For | |
example, the "Mobile Servers" MIPKind with the Path | |
'MIPKind[9947f340-397c-483b-9e03-f27253f7f403]' will have all configured | |
mobile servers listed under the configuration api folder path | |
'MIPKind[9947f340-397c-483b-9e03-f27253f7f403]/MIPItemFolder'. | |
.PARAMETER MipKind | |
Specifies a ConfigurationItem object with an ItemType value of 'MIPKind'. Use Get-MipKind, or "Get-ConfigurationItem '/MIPKindFolder' -ChildItems" to retrieve the appropriate MIPKind configuration items. | |
.PARAMETER Name | |
Specifies the display name of the MIPItem to be returned, with support for wildcards. The default behavior is to return all MIPItems under the provided MIPKind. | |
.PARAMETER LiteralName | |
Specifies the literal display name of the MIPItem to be returned. | |
.EXAMPLE | |
Get-MipKind -LiteralName 'Mobile Servers' | Get-MipItem | |
Get the MIPItems representing all configured Milestone Mobile Servers. | |
.EXAMPLE | |
Get-MipKind -LiteralName 'Mobile Servers' | Get-MipItem | Select-Object -First 1 -ExpandProperty Properties | Out-GridView | |
Gets the first Mobile Server MIPItem and displays the available property keys and values in a grid view dialog. | |
.EXAMPLE | |
$mobileKind = Get-MipKind -LiteralName 'Mobile Servers' | |
$mobileKind | Get-MipItem | Set-ConfigurationItemProperty -Key AdaptiveStreamingEnabled -Value 'False' -PassThru | Set-ConfigurationItem | |
Sets 'AdaptiveStreamingEnabled' to 'False' on all available Mobile Servers. | |
.EXAMPLE | |
Get-MipKind | Get-MipItem | |
Get all available MIPItems from all MIPKinds returned by Get-MipKind. | |
#> | |
[CmdletBinding(DefaultParameterSetName = 'Name')] | |
[OutputType([VideoOS.ConfigurationApi.ClientService.ConfigurationItem])] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'Name')] | |
[Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'LiteralName')] | |
[VideoOS.ConfigurationApi.ClientService.ConfigurationItem] | |
[ValidateScript({ | |
if ($_.ItemType -ne 'MIPKind') { | |
throw "Expected ConfigurationItem with ItemType 'MIPKind' but received '$($_.ItemType)' instead." | |
} | |
$true | |
})] | |
$MipKind, | |
[Parameter(ParameterSetName = 'Name')] | |
[string] | |
$Name = '*', | |
[Parameter(ParameterSetName = 'LiteralName')] | |
[string] | |
$LiteralName | |
) | |
process { | |
$matchFound = $false | |
$folderPath = '{0}/MIPItemFolder' -f $MipKind.Path | |
foreach ($item in Get-ConfigurationItem $folderPath -ChildItems) { | |
switch ($PSCmdlet.ParameterSetName) { | |
'Name' { | |
$pattern = [system.management.automation.wildcardpattern]::new($Name, [system.management.automation.wildcardoptions]::IgnoreCase) | |
if ($pattern.IsMatch($item.DisplayName)) { | |
$matchFound = $true | |
$item | |
} | |
} | |
'LiteralName' { | |
if ($item.DisplayName -eq $LiteralName) { | |
$matchFound = $true | |
$item | |
} | |
} | |
Default { | |
throw "ParameterSetName $_ not implemented." | |
} | |
} | |
} | |
if (-not $matchFound -and ($PSCmdlet.ParameterSetName -eq 'LiteralName' -or -not [wildcardpattern]::ContainsWildcardCharacters($Name))) { | |
if (-not [string]::IsNullOrEmpty($LiteralName)) { | |
$Name = $LiteralName | |
} | |
Write-Error "No item found with a display name matching '$Name'" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment