Remove-GitHubCodeScanningAnalysis
SYNOPSIS
Delete a code scanning analysis from a repository
SYNTAX
__AllParameterSets
Remove-GitHubCodeScanningAnalysis [-Owner] <string> [-Repo] <string> [-AnalysisId] <long>
[-ConfirmDelete <string>] [-Accept <string>] [-WhatIf] [-Confirm]
ALIASES
This cmdlet has the following aliases,
- Get-GHRemoveCodeScanningAnalysis
DESCRIPTION
The Remove-GitHubCodeScanningAnalysis cmdlet invokes the DELETE method of the /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id} endpoint (Delete a code scanning analysis from a repository)
Deletes a specified code scanning analysis from a repository.
You can delete one analysis at a time. To delete a series of analyses, start with the most recent analysis and work backwards. Conceptually, the process is similar to the undo function in a text editor.
When you list the analyses for a repository, one or more will be identified as deletable in the response:
“deletable”: true
An analysis is deletable when it’s the most recent in a set of analyses. Typically, a repository will have multiple sets of analyses for each enabled code scanning tool, where a set is determined by a unique combination of analysis values:
- ‘ref’
- ‘tool’
- ‘category’
If you attempt to delete an analysis that is not the most recent in a set, you’ll get a 400 response with the message:
Analysis specified is not deletable.
The response from a successful ‘DELETE’ operation provides you with two alternative URLs for deleting the next analysis in the set: ‘next_analysis_url’ and ‘confirm_delete_url’. Use the ‘next_analysis_url’ URL if you want to avoid accidentally deleting the final analysis in a set. This is a useful option if you want to preserve at least one analysis for the specified tool in your repository. Use the ‘confirm_delete_url’ URL if you are content to remove all analyses for a tool. When you delete the last analysis in a set, the value of ‘next_analysis_url’ and ‘confirm_delete_url’ in the 200 response is ‘null’.
As an example of the deletion process, let’s imagine that you added a workflow that configured a particular code scanning tool to analyze the code in a repository. This tool has added 15 analyses: 10 on the default branch, and another 5 on a topic branch. You therefore have two separate sets of analyses for this tool. You’ve now decided that you want to remove all of the analyses for the tool. To do this you must make 15 separate deletion requests. To start, you must find an analysis that’s identified as deletable. Each set of analyses always has one that’s identified as deletable. Having found the deletable analysis for one of the two sets, delete this analysis and then continue deleting the next analysis in the set until they’re all deleted. Then repeat the process for the second set. The procedure therefore consists of a nested loop:
Outer loop:
- List the analyses for the repository, filtered by tool.
- Parse this list to find a deletable analysis. If found:
Inner loop:
- Delete the identified analysis.
- Parse the response for the value of ‘confirm_delete_url’ and, if found, use this in the next iteration.
The above process assumes that you want to remove all trace of the tool’s analyses from the GitHub user interface, for the specified repository, and it therefore uses the ‘confirm_delete_url’ value. Alternatively, you could use the ‘next_analysis_url’ value, which would leave the last analysis in each set undeleted to avoid removing a tool’s analysis entirely.
OAuth app tokens and personal access tokens (classic) need the ‘repo’ scope to use this endpoint with private or public repositories, or the ‘public_repo’ scope to use this endpoint with only public repositories.
Endpoint: DELETE /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id} API version: 2026-03-10
EXAMPLES
EXAMPLE 1
Remove-GitHubCodeScanningAnalysis -Owner 'octocat' -Repo 'Hello-World' -AnalysisId 1
Invokes DELETE /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id}
PARAMETERS
-Accept
The Accept header (media type) of the request Default value: application/vnd.github+json
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-AnalysisId
The ID of the analysis, as returned from the ‘GET /repos/{owner}/{repo}/code-scanning/analyses’ operation.
Path parameter [ analysis_id ]
Type: System.Int64
DefaultValue: 0
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 2
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Confirm
Prompts you for confirmation before running the cmdlet.
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-ConfirmDelete
Allow deletion if the specified analysis is the last in a set. If you attempt to delete the final analysis in a set without setting this parameter to ‘true’, you’ll get a 400 response with the message: ‘Analysis is last of its type and deletion may result in the loss of historical alert data. Please specify confirm_delete.’
Query parameter [ confirm_delete ]
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Owner
The account owner of the repository. The name is not case sensitive.
Path parameter [ owner ]
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 0
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-Repo
The name of the repository without the ‘.git’ extension. The name is not case sensitive.
Path parameter [ repo ]
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 1
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
-WhatIf
Runs the command in a mode that only reports what would happen without performing the actions.
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
Objects with properties named like the path parameters can be piped to this function
{{ Fill in the Description }}
System.String
{{ Fill in the Description }}
System.Int64
{{ Fill in the Description }}
OUTPUTS
The response of the GitHub API (objects
{{ Fill in the Description }}
NOTES
OperationId: code-scanning/delete-analysis Category: code-scanning / code-scanning