/build/static/layout/Breadcrumb_cap_w.png

[I wrote] An open source Powershell Module for the Kace SMA API

[updated: 1/14/19] Changed project from GitLab to GitHub and added some newly updated cmdlets.

Like Powershell? Like KACE? If you're like me, you've noticed the KACE API sitting out there in right field, waiting on someone to hit a long fly. It's fantastic, but the barrier-to-entry might be a little daunting if you're unfamiliar with APIs.

I've written a small pet project called KaceSMA, a light weight SMA Powershell module that you can install on Windows,Mac,or Linux (mac/linux via PSCore). What it does is it essentially wraps the API in a Powershell compatibility layer and returns objects in a easy to digest format for all your automation needs. How do you use it you ask?

[edit] Updated way to install:

From a PS shell:

Install-Module KaceSMA

Here is the project: https://github.com/ArtisanByteCrafter/KaceSMA

Here's some basic examples of what you can do, along with the code to do it:

https://github.com/ArtisanByteCrafter/KaceSMA/wiki

  • Invoke a script against a list of machines
  • Add a task to an existing script
  • Return Machines with Encryption status of "Fully Encrypted"
  • Return SMA inventory machines with title 'Arduino' installed
  • Return all inventory members of smart label named "D - SmartLabel - Test"
  • Find the registry uninstall strings of all Software Inventory VMWare products
The only limit is really your API parameter creativity.

I expose the following Functions for use (today). More are being added often.

(Get-Command -Module KaceSMA).name
Get-SmaAgentlessInventory
Get-SmaArchiveAsset
Get-SmaAsset
Get-SmaAssetType
Get-SmaBarcodeAsset
Get-SmaCurrentUserAccount
Get-SmaMachineInventory
Get-SmaMachineProcess
Get-SmaMachineService
Get-SmaManagedInstall
Get-SmaManagedInstallMachineCompatibility
Get-SmaOperatingSystemInventory
Get-SmaReportingDefinition
Get-SmaScript
Get-SmaScriptDependency
Get-SmaScriptRunStatus
Get-SmaScriptTask
Get-SmaServiceDeskQueue
Get-SmaServiceDeskQueueField
Get-SmaServiceDeskTicket
Get-SmaServiceDeskTicketTemplate
Get-SmaSoftwareInventory
Get-SmaStartupProgramInventory
Get-SmaUserPermissions
Invoke-SmaScript
New-SmaAsset
New-SmaScript
New-SmaScriptTask
New-SmaServiceDeskTicket
Remove-SmaServiceDeskTicket
Set-SmaAssetAsArchived
Set-SmaMachineInventory
Set-SmaServiceDeskTicket

This isn't an exhaustive list of the API, there are a few I'm not exposing yet due to bugs on the SMA API end (dutifully ticketed and tracked already via support request with Quest), namely the Managed Install endpoint. If anyone has a request for a GET method that isn't covered, let me know- or submit a Pull Request!


You can install via "Install-Module KaceSMA", and update with "Update-Module KaceSMA". You can also clone the repository if you'd rather.

Here's an output if a simple asset retrieval:

BB3tPM.png


Thanks, and happy coding!

Nathaniel Webb (isudothings)


Comments

  • Good Job! In my case, I don't see most of the time I use the PowerShell module, but for lack of study, I could not understand very well how a Kace API works, because its module pushed me a lot - lpansarini 5 years ago
  • This is great! I was working on something similar when I ran across your creation here. I did have to make a change to the Get-ApiGETRequest.ps1 to get it to work for me, but it's working great now. - M1st3rS1r 5 years ago
    • Thanks! Out of curiosity, what did you need to change? - isudothings 5 years ago
      • I ended up having to remove line 31 ([Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12) and replaced it with the following:

        add-type @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
        }
        }
        "@


        $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
        [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
        [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy - M1st3rS1r 5 years ago
  • This was one of the jobs on my to-do list for next month, so I am chuffing delighted someone has done it (and probably done it better than I could have) and then shared it with the community. Thanks a bundle! - Honkytonk 5 years ago
    • Glad you like it, thanks :) - isudothings 5 years ago
  • This is wonderful! I plan to use it extensively to accomplish some goals. Thank you.
    One issue i'm having that perhaps i'm missing something simple is that when i attempt to use Get-SmaAsset or Get-SmaMachineInventory, it shows the proper count, but the details are limited to only 50 machines. How can i get all assets or inventory items? - dwestness 5 years ago
    • That's paging. Check my project wiki FAQ to see how to expand the results. https://github.com/ArtisanByteCrafter/KaceSMA/wiki/FAQ#q-my-queries-are-limited-to-50-results - isudothings 5 years ago
  • Do you know how to get the add_attachment working? The docs all show it written one way, yet I cannot get it to work no matter how it's written, it's as though it's documented, yet, doesn't exist. - GregThompson 4 years ago
    • I believe the developers have confirmed this is not actually exposed yet, even though the docs list it currently. - isudothings 4 years ago
  • Is there a way to get a report of how many agent licenses are in use vs available? - dunnenick 2 years ago
  • Thank you so much for this!

    Could you help me with an error I'm getting though?

    I am able to connect and get information from KACE SMA, but when I try to invoke or get a script I get a "Invoke-RestMethod : The remote server returned an error: (403) Forbidden." error. When I go the {KaceServer}/api the webpage says "{"error": "API disabled."}"

    Do you know what's causing this and how to fix it? - JKith 1 year ago
This post is locked

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ