cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting Command Results to a CSV

urvashi
Iron I
Iron I

Hello all, 

Sharing a Powershell script that was posted in the JumpCloud Slack Lounge by @simonbh-cbu in response to a question about exporting command results to a csv. Note that this uses the JumpCloud API.

 

$path = "../.apikey"
$jcApiKey = Get-Content $path
# You will need to update the commandID with the unique ID assigned to the command. 
# The ID can be found in the JC Console URI when editing the command
$commandID = "642d7231a2e951e5817aaa00"

# Check if JumpCloud module is installed, if not, install it and connect.
try {
    if (-not (Get-Module -ListAvailable JumpCloud)) {
        Install-Module -Name JumpCloud -Scope CurrentUser -Force
    }
    Import-Module -Name JumpCloud
    Connect-JCOnline -JumpCloudApiKey $jcApiKey
} catch {
    Write-Error "Something went wrong connecting to JumpCloud! $($_.Exception.Message)" -ErrorAction Stop
}

try {
    Get-JCCommandResult -CommandID $commandID |
        Select-Object -Property requestTime,responseTime,system,exitCode |
        Export-Csv -Path .\command_results.csv -NoTypeInformation
} catch {
    Write-Error "Something went wrong when checking the command result! $($_.Exception.Message)" -ErrorAction Stop
}

 Thank you @simonbh-cbu for your contribution to the JumpCloud Community, we appreciate you! 

Urvashi

4 REPLIES 4

red66
Novitiate I

hi, where we put the api key? 

Hi @red66 in the example above from @simonbh-cbu the API will be in a text file on your system. The first line in the script is for the file path, and the 2nd line is to read the API key from that file path and put it into the $path variable. 

If you're comfortable having the API key in plain text in your script (it will be visible if logging is enabled), you could skip the first line and paste it into the second line instead of using the Get-Content command. 

Hope this helps! Let me know if you have any other questions. 

thank you for the guide @urvashi. its worked on my side.

Glad to hear that! 🙂