Skip to content

Set-GitHubSecret

SYNOPSIS

Updates a GitHub secret for an organization, repository, or user.

SYNTAX

AuthenticatedUser (Default)

Set-GitHubSecret -Name <String> -Value <String> [-Context <Object>] [-ProgressAction <ActionPreference>]
 [-WhatIf] [-Confirm] [<CommonParameters>]

Environment

Set-GitHubSecret -Owner <String> -Repository <String> -Environment <String> -Name <String> -Value <String>
 [-Context <Object>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Repository

Set-GitHubSecret -Owner <String> -Repository <String> -Name <String> -Value <String> [-Context <Object>]
 [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Organization

Set-GitHubSecret -Owner <String> -Name <String> -Value <String> [-Visibility <String>]
 [-SelectedRepositories <UInt64[]>] [-Context <Object>] [-ProgressAction <ActionPreference>] [-WhatIf]
 [-Confirm] [<CommonParameters>]

DESCRIPTION

This function updates a secret in a GitHub repository, environment, or organization. It encrypts the secret value before storing it and supports different visibility levels.

EXAMPLES

EXAMPLE 1

$secret = ConvertTo-SecureString "my-secret-value" -AsPlainText -Force
Set-GitHubSecret -Repository 'MyRepo' -Owner 'MyUser' -Name 'MySecret' -Value $secret

Updates the secret MySecret in the MyRepo repository for the owner MyUser.

EXAMPLE 2

$params = @{
    Organization = 'MyOrg'
    Name         = 'MySecret'
    Type         = 'actions'
    Value        = (ConvertTo-SecureString "my-secret-value" -AsPlainText -Force)
    Private      = $true
}
Set-GitHubSecret @params

Updates the secret MySecret at the organization level for GitHub Actions, setting visibility to private.

EXAMPLE 3

$params = @{
    Owner      = 'MyUser'
    Repository = 'MyRepo'
    Environment = 'Production'
    Name       = 'MySecret'
    Value      = (ConvertTo-SecureString "my-secret-value" -AsPlainText -Force)
}
Set-GitHubSecret @params

Updates the secret MySecret in the Production environment of the MyRepo repository for MyUser.

PARAMETERS

-Owner

The account owner of the repository. The name is not case sensitive.

Type: String
Parameter Sets: Environment, Repository, Organization
Aliases: Organization, User

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Repository

The name of the repository. The name is not case sensitive.

Type: String
Parameter Sets: Environment, Repository
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Environment

The name of the repository environment.

Type: String
Parameter Sets: Environment
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Name

The name of the secret to be updated.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Value

The secret value to be stored, provided as a SecureString.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Visibility

The visibility of the secret when updating an organization secret. Can be private, selected, or all.

Type: String
Parameter Sets: Organization
Aliases:

Required: False
Position: Named
Default value: Private
Accept pipeline input: False
Accept wildcard characters: False

-SelectedRepositories

The IDs of the repositories to which the secret is available. Used only when the -Visibility parameter is set to selected.

Type: UInt64[]
Parameter Sets: Organization
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Context

The context to run the command in. Used to get the details for the API call. Can be either a string or a GitHubContext object.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-GitHubContext)
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

GitHubSecret

NOTES

https://psmodule.io/GitHub/Functions/Secrets/Set-GitHubSecret/