forked from plmcgrn/posh-ic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set-ICMediaServerAcceptConnections.ps1
75 lines (66 loc) · 2.72 KB
/
Set-ICMediaServerAcceptConnections.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
# AUTHOR : Paul McGurn
# DATE : 02/10/2021
#>
#NOTE: Media Server REST API is not enabled by default. If this command returns a error 404 or 401, that is likely why.
function Set-ICMediaServerAcceptConnections() {
<#
.SYNOPSIS
Configures the media server to accept or reject new sessions, then returns array with statuses
.DESCRIPTION
Configures the media server to accept or reject new sessions, then returns array with statuses
.PARAMETER Server
The media server to configure
.PARAMETER User
The media server username to log on with
.PARAMETER Password
The media server password to log on with. Must be of type System.SecureString for adequate runtime security.
.PARAMETER AcceptSessions
Whether the server should accept sessions. Use $true or $false.
.PARAMETER UseHttps
Whether the connection should use http (default) or https. The Media server needs to have these two settings enabled
in order to use https
* Recording Retrieval Use Mutual Authentication
* Recording Retrieval HTTPS Required
.EXAMPLE
$user = 'someuser'
$password = ConvertTo-SecureString 'Super$strong##' -AsPlainText
$s = Set-ICMediaServerAcceptConnections -Server 'mymediaserver.example.com' -User $user -Password $password -AcceptConnections $false
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)] [Alias("Computer", "MediaServer")] $Server,
[Parameter(Mandatory = $true)] [Alias("username")] $User,
[Parameter(Mandatory = $true)] [Alias("pass")] [SecureString]$Password,
[Parameter(Mandatory = $false)] [bool] $acceptSessions = $true,
[Parameter(Mandatory = $false)] [bool] $UseHttps = $false
)
#TODO: Allow more precision, vs. disabling all command servers
#Get the list of command servers
$servers = Get-ICMediaServerStatus -Computer $Server -User $User -Password $Password
$cred = New-Object System.Management.Automation.PSCredential $User, $Password
#set state for each command server
foreach ($s in $servers) {
$id = $s.id
$name = $s.icServerName
if ($UseHttps) {
$protocol = 'https://'
}
else {
$protocol = 'http://'
}
$uri = $uri = $protocol + $server + ":8102/api/v1/commandservers/${id}"
$headers = @{
'Content-Type' = 'application/json'
}
$body = ConvertTo-Json @{
'acceptSessions' = $acceptSessions
}
#TODO: Configure support for HTTPS
$response = Invoke-RestMethod -Uri $uri -Method PATCH -Headers $headers -Body $body -Credential $cred -AllowUnencryptedAuthentication
Write-Verbose "Status of $name"
$response | Out-String | Write-Verbose
}
$servers = Get-ICMediaServerStatus -Computer $Server -User $User -Password $Password
return $servers
}