08-08-2023 08:44 AM
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
08-22-2023 04:37 AM
hi, where we put the api key?
08-22-2023 06:37 AM
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.
08-22-2023 09:43 PM - edited 08-22-2023 09:44 PM
thank you for the guide @urvashi. its worked on my side.
08-23-2023 05:02 AM
Glad to hear that! 🙂
New to the site? Take a look at these additional resources:
Ready to join us? You can register here.