Public/ScriptedActions.ps1

Function Remove-NmeScriptedAction {
    <#

    .SYNOPSIS

    Delete scripted action.

    .DESCRIPTION

    Delete scripted action.

    This function calls the /api/v1/scripted-actions/{id} endpoint of the NME REST API, using the delete method.


    .PARAMETER Id

    ID of scripted Action

    .PARAMETER NmeDeleteScriptedActionRequest

    Requires an NmeDeleteScriptedActionRequest object, as generated by the New-NmeDeleteScriptedActionRequest command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeDeleteScriptedActionRequest"){$true} else{throw " is not a NmeDeleteScriptedActionRequest object."}})]$NmeDeleteScriptedActionRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeDeleteScriptedActionRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id$QueryString" -Method delete -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob')
        $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Set-NmeScriptedAction {
    <#

    .SYNOPSIS

    Partially update scripted action.

    .DESCRIPTION

    Partially update scripted action.

    This function calls the /api/v1/scripted-actions/{id} endpoint of the NME REST API, using the patch method.


    .PARAMETER Id

    ID of scripted Action

    .PARAMETER NmeCreateScriptedActionRequest

    Requires an NmeCreateScriptedActionRequest object, as generated by the New-NmeCreateScriptedActionRequest command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeCreateScriptedActionRequest"){$true} else{throw " is not a NmeCreateScriptedActionRequest object."}})]$NmeCreateScriptedActionRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeCreateScriptedActionRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id$QueryString" -Method patch -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJobAndScriptedAction')
        $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Remove-NmeScriptedActionSchedule {
    <#

    .SYNOPSIS

    Delete Azure runbook scripted action schedule configuration.

    .DESCRIPTION

    Delete Azure runbook scripted action schedule configuration.

    This function calls the /api/v1/scripted-actions/{id}/schedule endpoint of the NME REST API, using the delete method.


    .PARAMETER Id

    ID of scripted Action

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id
    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id/schedule$Querystring" -Method delete -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Get-NmeScriptedActionSchedule {
    <#

    .SYNOPSIS

    Get Azure runbook scripted action schedule configuration.

    .DESCRIPTION

    Get Azure runbook scripted action schedule configuration.

    This function calls the /api/v1/scripted-actions/{id}/schedule endpoint of the NME REST API, using the get method.


    .PARAMETER Id

    ID of scripted Action

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id
    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id/schedule$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeScriptedActionScheduleRestModel')
        $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function New-NmeScriptedActionSchedule {
    <#

    .SYNOPSIS

    Schedule Azure runbook scripted action execution in Automation account.

    .DESCRIPTION

    Schedule Azure runbook scripted action execution in Automation account.

    This function calls the /api/v1/scripted-actions/{id}/schedule endpoint of the NME REST API, using the post method.


    .PARAMETER Id

    ID of scripted Action

    .PARAMETER NmeScheduleAzureScripedActionPayload

    Requires an NmeScheduleAzureScripedActionPayload object, as generated by the New-NmeScheduleAzureScripedActionPayload command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeScheduleAzureScripedActionPayload"){$true} else{throw " is not a NmeScheduleAzureScripedActionPayload object."}})]$NmeScheduleAzureScripedActionPayload
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeScheduleAzureScripedActionPayload | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id/schedule$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeScriptedActionScheduleRestModel')
        $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Get-NmeScriptedActions {
    <#

    .SYNOPSIS

    Get scripted actions.

    .DESCRIPTION

    Get scripted actions.

    This function calls the /api/v1/scripted-actions endpoint of the NME REST API, using the get method.




    #>


    [CmdletBinding()]
    Param(

    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeScriptedAction')
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function New-NmeScriptedActions {
    <#

    .SYNOPSIS

    Create scripted action.

    .DESCRIPTION

    Create scripted action.

    This function calls the /api/v1/scripted-actions endpoint of the NME REST API, using the post method.


    .PARAMETER NmeCreateScriptedActionRequest

    Requires an NmeCreateScriptedActionRequest object, as generated by the New-NmeCreateScriptedActionRequest command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeCreateScriptedActionRequest"){$true} else{throw " is not a NmeCreateScriptedActionRequest object."}})]$NmeCreateScriptedActionRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeCreateScriptedActionRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJobAndScriptedAction')
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function New-NmeRunbookScriptedAction {
    <#

    .SYNOPSIS

    Run Azure runbook scripted action in Automation account.

    .DESCRIPTION

    Run Azure runbook scripted action in Automation account.

    This function calls the /api/v1/scripted-actions/{id}/execution endpoint of the NME REST API, using the post method.


    .PARAMETER Id

    ID of scripted Action

    .PARAMETER NmeRunAzureScripedActionPayload

    Requires an NmeRunAzureScripedActionPayload object, as generated by the New-NmeRunAzureScripedActionPayload command.

    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Id,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeRunAzureScripedActionPayload"){$true} else{throw " is not a NmeRunAzureScripedActionPayload object."}})]$NmeRunAzureScripedActionPayload
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeRunAzureScripedActionPayload | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/scripted-actions/$Id/execution$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeJob')
        $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}