functions/Set-ZGMaintenance.ps1
|
function Set-ZGMaintenance { param ( [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $True)] [long] $MaintenanceId, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $True)] [long[]] $HostId, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [string] $Name, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [string] $Description, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [datetime] $from, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [datetime] $to, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $false)] [hashtable[]] $Timeperiod ) Begin { $parameters = @{ maintenanceid = $MaintenanceId } if ($PSBoundParameters.ContainsKey('HostId')) { $parameters.hosts = (Get-ZGHost -HostId $HostId | Select-Object -Property hostid) } if ($PSBoundParameters.ContainsKey('Name')) { $parameters.name = $Name } if ($PSBoundParameters.ContainsKey('Description')) { $parameters.description = $Description } if ($PSBoundParameters.ContainsKey('From')) { $parameters.active_since = [int][double]::Parse((Get-Date $From -UFormat %s)) } if ($PSBoundParameters.ContainsKey('To')) { $parameters.active_till = [int][double]::Parse((Get-Date $To -UFormat %s)) } if ($PSBoundParameters.ContainsKey('Timeperiod')) { $parameters.timeperiods = $Timeperiod } } Process { $response = Invoke-ZGRequest -Method "POST" -Body @{ "method" = "maintenance.update" "params" = $parameters "auth" = $script:RequestAuth } $response.result } } |