Modules/services.psm1
# GET/rest/v1.0/dd-systems/{SYSTEM-ID}/services/ntp function Get-DDServices { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $false, ParameterSetName = 'ntp')] [switch]$ntp, $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "GET" } process { switch ($PsCmdlet.ParameterSetName) { default { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/services" } 'ntp' { $apiver = "rest/v1.0" $uri = "dd-systems/$($SYSTEM_ID)/services/ntp" } } $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $body RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response.services | Select-Object -ExcludeProperty link } 'ntp' { $response | Select-Object -ExcludeProperty link,servers -ExpandProperty servers } } } } # /rest/v2.0/dd-systems/{SYSTEM-ID}/services/ntp function Set-DDntpservice { [CmdletBinding()] param ( [CmdletBinding()] [Parameter(Mandatory = $true, ParameterSetName = 'delete_servers')] [switch]$delete_servers, [Parameter(Mandatory = $true, ParameterSetName = 'add_servers')] [switch]$add_servers, [Parameter(Mandatory = $true, ParameterSetName = 'add_servers')] [Parameter(Mandatory = $true, ParameterSetName = 'delete_servers')] [string[]]$servers, # # [Parameter(Mandatory = $true, ParameterSetName = 'disable')] [switch]$disable, [Parameter(Mandatory = $true, ParameterSetName = 'enable')] [switch]$enable, $SYSTEM_ID = $Global:DD_UUID, $body = @{} ) begin { $Response = @() $METHOD = "PUT" } process { $apiver = "rest/v2.0" $uri = "dd-systems/$($SYSTEM_ID)/services/ntp" $json = @{ operation = $PsCmdlet.ParameterSetName } # creating body by pset switch ($PsCmdlet.ParameterSetName) { { ($_ -eq 'add_servers') -or ( $_ -eq 'delete_servers') } { $json.Add('servers', @{'server' = $servers}) } } $json = $json | ConvertTo-Json Write-Verbose ($json | out-string) $parameters = @{ uri = $uri apiver = $apiver Method = $METHOD body = $json RequestMethod = "REST" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-DDapirequest @Parameters } catch { Get-DDWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { $response | Select-Object -ExcludeProperty link,servers -ExpandProperty servers } } } } |