custom/generated/Set-JcSdkCommand.ps1
<# .Synopsis This endpoint Updates a command based on the command ID and returns the modified command record. #### Sample Request ``` curl -X PUT https://console.jumpcloud.com/api/commands/{CommandID} \\ -H 'Accept: application/json' \\ -H 'Content-Type: application/json' \\ -H 'x-api-key: {API_KEY}' \\ -d '{ \t\"name\":\"Test API Command\", \t\"command\":\"String\", \t\"user\":\"{UserID}\", \t\"schedule\":\"\", \t\"timeout\":\"100\" }' ``` .Description This endpoint Updates a command based on the command ID and returns the modified command record. #### Sample Request ``` curl -X PUT https://console.jumpcloud.com/api/commands/{CommandID} \\ -H 'Accept: application/json' \\ -H 'Content-Type: application/json' \\ -H 'x-api-key: {API_KEY}' \\ -d '{ \t\"name\":\"Test API Command\", \t\"command\":\"String\", \t\"user\":\"{UserID}\", \t\"schedule\":\"\", \t\"timeout\":\"100\" }' ``` .Example PS C:\> Set-JcSdkCommand -Id:(<string>) -Body:(<JumpCloud.SDK.V1.Models.Command>) ---- ---------- Command1 String CommandRunners String CommandType String Files String LaunchType String ListensTo String Name String Organization String Schedule String ScheduleRepeatType String ScheduleYear Int Shell String Sudo Boolean Template String Timeout String TimeToLiveSeconds Int Trigger String User String .Example PS C:\> Set-JcSdkCommand -Id:(<string>) -Command:(<string>) -CommandType:(<string>) -Name:(<string>) -CommandRunners:(<string[]>) -Files:(<string[]>) -LaunchType:(<string>) -ListensTo:(<string>) -Organization:(<string>) -Schedule:(<string>) -ScheduleRepeatType:(<string>) -ScheduleYear:(<int>) -Shell:(<string>) -Sudo:(<switch>) -Template:(<string>) -TimeToLiveSeconds:(<int>) -Timeout:(<string>) -Trigger:(<string>) -User:(<string>) ---- ---------- Command1 String CommandRunners String CommandType String Files String LaunchType String ListensTo String Name String Organization String Schedule String ScheduleRepeatType String ScheduleYear Int Shell String Sudo Boolean Template String Timeout String TimeToLiveSeconds Int Trigger String User String .Inputs JumpCloud.SDK.V1.Models.ICommand .Inputs JumpCloud.SDK.V1.Models.IJumpCloudApiIdentity .Outputs JumpCloud.SDK.V1.Models.ICommand .Notes COMPLEX PARAMETER PROPERTIES To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables. BODY <ICommand>: Command1 <String>: The command to execute on the server. CommandType <String>: The Command OS Name <String>: [CommandRunners <String[]>]: An array of IDs of the Command Runner Users that can execute this command. [Files <String[]>]: An array of file IDs to include with the command. [LaunchType <String>]: How the command will execute. [ListensTo <String>]: [Organization <String>]: The ID of the organization. [Schedule <String>]: A crontab that consists of: [ (seconds) (minutes) (hours) (days of month) (months) (weekdays) ] or [ immediate ]. If you send this as an empty string, it will run immediately. [ScheduleRepeatType <String>]: When the command will repeat. [ScheduleYear <Int32?>]: The year that a scheduled command will launch in. [Shell <String>]: The shell used to run the command. [Sudo <Boolean?>]: [Template <String>]: The template this command was created from [TimeToLiveSeconds <Int32?>]: Time in seconds a command can wait in the queue to be run before timing out [Timeout <String>]: The time in seconds to allow the command to run for. The maximum value is 86400 seconds (1 day). [Trigger <String>]: The name of the command trigger. [User <String>]: The ID of the system user to run the command as. This field is required when creating a command with a commandType of "mac" or "linux". INPUTOBJECT <IJumpCloudApiIdentity>: [Id <String>]: [SystemId <String>]: [SystemuserId <String>]: [Triggername <String>]: .Link https://github.com/TheJumpCloud/jcapi-powershell/tree/master/SDKs/PowerShell/JumpCloud.SDK.V1/docs/exports/Set-JcSdkCommand.md #> Function Set-JcSdkCommand { [OutputType([JumpCloud.SDK.V1.Models.ICommand])] [CmdletBinding(DefaultParameterSetName='SetExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] Param( [Parameter(ParameterSetName='Set', Mandatory)] [Parameter(ParameterSetName='SetExpanded', Mandatory)] [JumpCloud.SDK.V1.Category('Path')] [System.String] # . ${Id}, [Parameter(ParameterSetName='SetViaIdentity', Mandatory, ValueFromPipeline)] [Parameter(ParameterSetName='SetViaIdentityExpanded', Mandatory, ValueFromPipeline)] [JumpCloud.SDK.V1.Category('Path')] [JumpCloud.SDK.V1.Models.IJumpCloudApiIdentity] # Identity Parameter # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. ${InputObject}, [Parameter(ParameterSetName='Set', Mandatory, ValueFromPipeline)] [Parameter(ParameterSetName='SetViaIdentity', Mandatory, ValueFromPipeline)] [JumpCloud.SDK.V1.Category('Body')] [JumpCloud.SDK.V1.Models.ICommand] # Command # To construct, see NOTES section for BODY properties and create a hash table. ${Body}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] [Parameter(ParameterSetName='SetViaIdentityExpanded', Mandatory)] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The command to execute on the server. ${Command}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] [Parameter(ParameterSetName='SetViaIdentityExpanded', Mandatory)] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The Command OS ${CommandType}, [Parameter(ParameterSetName='SetExpanded', Mandatory)] [Parameter(ParameterSetName='SetViaIdentityExpanded', Mandatory)] [JumpCloud.SDK.V1.Category('Body')] [System.String] # . ${Name}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [AllowEmptyCollection()] [JumpCloud.SDK.V1.Category('Body')] [System.String[]] # An array of IDs of the Command Runner Users that can execute this command. ${CommandRunners}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [AllowEmptyCollection()] [JumpCloud.SDK.V1.Category('Body')] [System.String[]] # An array of file IDs to include with the command. ${Files}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # How the command will execute. ${LaunchType}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # . ${ListensTo}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The ID of the organization. ${Organization}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # A crontab that consists of: [ (seconds) (minutes) (hours) (days of month) (months) (weekdays) ] or [ immediate ]. # If you send this as an empty string, it will run immediately. ${Schedule}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # When the command will repeat. ${ScheduleRepeatType}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.Int32] # The year that a scheduled command will launch in. ${ScheduleYear}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The shell used to run the command. ${Shell}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.Management.Automation.SwitchParameter] # . ${Sudo}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The template this command was created from ${Template}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.Int32] # Time in seconds a command can wait in the queue to be run before timing out ${TimeToLiveSeconds}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The time in seconds to allow the command to run for. # The maximum value is 86400 seconds (1 day). ${Timeout}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The name of the command trigger. ${Trigger}, [Parameter(ParameterSetName='SetExpanded')] [Parameter(ParameterSetName='SetViaIdentityExpanded')] [JumpCloud.SDK.V1.Category('Body')] [System.String] # The ID of the system user to run the command as. # This field is required when creating a command with a commandType of "mac" or "linux". ${User}, [Parameter(DontShow)] [JumpCloud.SDK.V1.Category('Runtime')] [System.Management.Automation.SwitchParameter] # Wait for .NET debugger to attach ${Break}, [Parameter(DontShow)] [ValidateNotNull()] [JumpCloud.SDK.V1.Category('Runtime')] [JumpCloud.SDK.V1.Runtime.SendAsyncStep[]] # SendAsync Pipeline Steps to be appended to the front of the pipeline ${HttpPipelineAppend}, [Parameter(DontShow)] [ValidateNotNull()] [JumpCloud.SDK.V1.Category('Runtime')] [JumpCloud.SDK.V1.Runtime.SendAsyncStep[]] # SendAsync Pipeline Steps to be prepended to the front of the pipeline ${HttpPipelinePrepend}, [Parameter(DontShow)] [JumpCloud.SDK.V1.Category('Runtime')] [System.Uri] # The URI for the proxy server to use ${Proxy}, [Parameter(DontShow)] [ValidateNotNull()] [JumpCloud.SDK.V1.Category('Runtime')] [System.Management.Automation.PSCredential] # Credentials for a proxy server to use for the remote call ${ProxyCredential}, [Parameter(DontShow)] [JumpCloud.SDK.V1.Category('Runtime')] [System.Management.Automation.SwitchParameter] # Use the default credentials for the proxy ${ProxyUseDefaultCredentials} ) Begin { $Results = @() $PSBoundParameters.Add('HttpPipelineAppend', { param($req, $callback, $next) # call the next step in the Pipeline $ResponseTask = $next.SendAsync($req, $callback) $global:JCHttpRequest = $req # $global:JCHttpRequestContent = If (-not [System.String]::IsNullOrEmpty($req.Content)) { $req.Content.ReadAsStringAsync() } $global:JCHttpResponse = $ResponseTask # $global:JCHttpResponseContent = If (-not [System.String]::IsNullOrEmpty($ResponseTask.Result.Content)) { $ResponseTask.Result.Content.ReadAsStringAsync() } Return $ResponseTask } ) } Process { $maxRetries = 4 $resultCounter = 0 :retryLoop do { $resultCounter++ $Results = JumpCloud.SDK.V1.internal\Set-JcSdkInternalCommand @PSBoundParameters -errorAction SilentlyContinue -errorVariable sdkError If ($sdkError){ If ($resultCounter -eq $maxRetries){ throw $sdkError } If ($JCHttpResponse.Result.StatusCode -eq "503") { Write-Warning ("503: Service Unavailable - retrying in " + ($resultCounter * 5) + " seconds.") } else { throw $sdkError } } else { break retryLoop } Start-Sleep -Seconds ($resultCounter * 5) } while ($resultCounter -lt $maxRetries) } End { Write-Debug ('HttpRequest: ' + $JCHttpRequest); # Write-Debug ('HttpRequestContent: ' + $JCHttpRequestContent.Result); Write-Debug ('HttpResponse: ' + $JCHttpResponse.Result); # Write-Debug ('HttpResponseContent: ' + $JCHttpResponseContent.Result); # Clean up global variables $GlobalVars = @('JCHttpRequest', 'JCHttpRequestContent', 'JCHttpResponse', 'JCHttpResponseContent') $GlobalVars | ForEach-Object { If ((Get-Variable -Scope:('Global')).Where( { $_.Name -eq $_ })) { Remove-Variable -Name:($_) -Scope:('Global') } } Return $Results } } |