Skip to content

New-PSCredential

SYNOPSIS

Creates a new PSCredential object.

SYNTAX

New-PSCredential [[-Username] <String>] [[-Password] <Object>] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

This function generates a PSCredential object using a specified username and password. The password can be provided as a secure string or a plain text string, which will be converted into a SecureString automatically.

EXAMPLES

EXAMPLE 1

New-PSCredential

Prompts the user for a username and password and returns a PSCredential object.

EXAMPLE 2

New-PSCredential -Username 'admin' -Password (ConvertTo-SecureString 'P@ssw0rd!' -AsPlainText -Force)

Creates a PSCredential object for the specified username and password.

PARAMETERS

-Username

Specifies the username for the PSCredential object.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: (Read-Host -Prompt 'Enter a username')
Accept pipeline input: False
Accept wildcard characters: False

-Password

Specifies the password for the PSCredential object. Accepts a secure string or plain text.

Type: Object
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: (Read-Host -Prompt 'Enter Password' -AsSecureString)
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

System.Management.Automation.PSCredential

NOTES

https://psmodule.io/PSCredential/Functions/New-PSCredential/