Giter Site home page Giter Site logo

devynspencer / powershell-sdp-cloud Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 200 KB

Interact with the ManageEngine ServiceDeskPlus OnDemand (cloud) API using PowerShell.

License: MIT License

PowerShell 100.00%
manage-engine servicedeskplus zoho powershell automation powershell-module

powershell-sdp-cloud's Introduction

ServiceDeskPlusCloud

PowerShell module focused on manipulating the ServiceDeskPlus OnDemand (cloud) API.

Getting Started

In order to obtain a temporary authorization code to authenticate to the API with, you first need to register a self-client application via the ZOHO API Client Console. See the ManageEngine API documentation on generating access and refresh tokens for more information.

Follow the steps in the documentation to generate a temporary authentication code and supply the value to the GrantToken parameter of New-ZohoAccessToken or download the self_client.json file from the API client console and supply the path via the FilePath parameter.

# Replace the following examples with those obtained from the Zoho developer portal, obviously
$NewTokenParams = @{
  GrantToken = '1000.f74e7b6fc16c95bbc1fa2f067962f84b.9768e796b6273774817032613ba6892a'
  ClientId = '1000.15S25B602CISR5WO9RUZ8UT39O3RIH'
  ClientSecret = '9ea302935eb150d9d6cbefd35b1eb8891332d815b8'
}

$ZohoAuth = New-ZohoAccessToken @NewTokenParams

Request and store the access token in the local secret store:

Request-ZohoAccessToken -Verbose

Module functions will retrieve the access token from the store as needed, so it doesn't need to be specified:

$RequestParams = @{
    Status = 'Open', 'Onhold'
    Portal = 'is'
    Technician = '[email protected]'
}

$Tickets = Find-ServiceDeskRequest @RequestParams

Default Parameters

PowerShell allows you to save default values for parameters via the PSDefaultParameterValues variable.

Add defaults to your PowerShell profile to limit the number of parameters that need to be specified when executing ServiceDeskPlusCloud functions:

# Microsoft.PowerShell_Profile.ps1

$PSDefaultParameterValues['*-ServiceDeskPlus*:Portal'] = 'is'
$PSDefaultParameterValues['Find-ServiceDeskPlusRequest:Technician'] = '[email protected]'

Testing

First install the Pester module:

Install-Module Pester -Force

You're ready to run Pester tests:

Invoke-Pester

Environment

This module attempts to reuse environment data from a variety of sources, namely environment variables and the local secret store. Be sure to set the following environment variables or update the configurations accordingly.

Description Secret Name Environment Variable
The consumer key generated from the connected application. CLIENT_ID ZOHO_CLIENT_ID
The consumer secret generated from the connected application. CLIENT_SECRET ZOHO_CLIENT_SECRET
OAuth token used to obtain new access tokens. Unlimited lifetime, until revoked by the user. REFRESH_TOKEN ZOHO_REFRESH_TOKEN
OAuth token sent to server to access protected resources. ACCESS_TOKEN ZOHO_ACCESS_TOKEN
Unique identifier of the ServiceDesk Plus Cloud instance to interact with. PORTAL_NAME ZOHO_PORTAL_NAME
Base URI of the ServiceDesk Plus Cloud instance to interact with. BASE_URI ZOHO_BASE_URI

Secret Store

This module uses the Microsoft.PowerShell.SecretStore module to store sensitive information like API tokens and passwords. Before using the module, you need to configure the secret store and store required secrets:

# Install required modules
Install-Module Microsoft.PowerShell.SecretManagement
Install-Module Microsoft.PowerShell.SecretStore

# Configure secret store settings
$SecretStoreParams = @{
    Authentication = 'Password'
    Password = (ConvertTo-SecureString -AsPlainText -Force 'mypassword12345')
    Scope = 'CurrentUser'
    Interaction = 'None'
    Confirm = $false
}

Set-SecretStoreConfiguration @SecretStoreParams

# Replace the values with your own, obviously
$ZohoSecrets = @(
    @{ Name = 'CLIENT_ID'; Value = '...' },
    @{ Name = 'CLIENT_SECRET'; Value = '...' },
    @{ Name = 'REFRESH_TOKEN'; Value = '...' },
    @{ Name = 'PORTAL_NAME'; Value = '...' },
    @{ Name = 'BASE_URI'; Value = 'https://sdp.example.com/' }
)

# Register a new secret vault and store the secrets
Register-SecretVault -ModuleName Microsoft.PowerShell.SecretStore -Name Zoho
$ZohoSecrets | % { Set-Secret -Name $_.Name -Secret $_.Value -Vault Zoho }

Environment Variables

Alternatively, you can set the following environment variables to avoid using the secret store:

ZOHO_CLIENT_ID
ZOHO_CLIENT_SECRET
ZOHO_REFRESH_TOKEN
ZOHO_ACCESS_TOKEN
ZOHO_PORTAL_NAME
ZOHO_BASE_URI

powershell-sdp-cloud's People

Contributors

devynspencer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

powershell-sdp-cloud's Issues

Export inaccessible resources and types

  • Get large number of changes (but limit returned fields to those that will be exported), storing all unique values for properties like template.name, change_type.name etc.

Add function: Rename-ServiceDeskRequest

Not a direct consumer of an API resource - more of a convenience function.

# Rename a ticket
Get-ServiceDeskRequest -Id 12345 | Rename-ServiceDeskRequest -Subject "New subject here"

# Add a prefix to an existing ticket
Get-ServiceDeskRequest -Id 12345 | Rename-ServiceDeskRequest -Prefix "FIX: "

# Add a suffix to an existing ticket
Get-ServiceDeskRequest -Id 12345 | Rename-ServiceDeskRequest -Suffix "- DUPLICATE"

Add function: *-ServiceDeskTask

Add-ServiceDeskTask -Request 12345 -Title "Perform action xyz" -Priority High
Update-ServiceDeskTask -Request 12345 -Title "Perform action abc" -Priority Low
Remove-ServiceDeskTask -Request 12345 -Id 1
Resolve-ServiceDeskTask -Request 12345 -Id 1

Add tests for basic module structure

Add Pester tests for basic module structure, features, manifest metadata and similar. It should be easy to identify modules that have drifted from the set standard.

Add function: Send-ServiceDeskMessage

There doesn't appear to be a built-in way to send messages via the API. That said, an email with the correct subject could be generated, and the ticket email determined and included as well.

Get-ServiceDeskRequest -Id 12345 | Send-ServiceDeskMessage -Text "Here is an email update to a specific user. It will be added to the ticket conversation." -To devyn.spencer@example.com -Cc worker.bee@example.com

Add function New-ServiceDeskTask

  • Create new standalone task (i.e. using /api/v3/tasks endpoint)
  • Create new child task on request
  • Create new child task on problem
  • Create new child task on change
  • Create new child task on project
  • Create new child task on project milestone
  • Create new child task on release

Pass boilerplate API parameters via the pipeline

Get-ServiceDeskRequest -AccessToken $AccessToken -Portal "helpdesk" -Id 12345 | Suspend-ServiceDeskRequest -Until "12/11/2020"

Get-ServiceDeskRequest -AccessToken $AccessToken -Portal "helpdesk" -Id 12345
    | Set-ServiceDeskRequest -Subject "New subject" | Resolve-ServiceDeskRequest

Standardize output objects across all resource types

  • Convert/format property names in PascalCase instead of snakeCamel_shitshow case.
  • Include response codes and other useful information about the request
  • Remove pagination information
  • Add tests to verify consistency across all resource types
  • Document expected output format

Add function to format solution bodies

Allow for a number of source formats, but ideally we could focus on markdown.

It would be huge to be able to sync solutions against a directory of markdown files (potentially with header data for indicating the solution id, tags etc).

Add function: *-ServiceDeskProblem

New-ServiceDeskProblem
Remove-ServiceDeskProblem

# Unsure of correct verb to attach request(s) to a problem
Add-ServiceDeskRequest
Add-ServiceDeskProblem
Connect-ServiceDeskProblem
Join-ServiceDeskProblem
Push-ServiceDeskRequest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.