Get-Credentials

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Justin King Justin King 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34502
    Profile photo of Helder Guzman
    Helder Guzman
    Participant

    Hi

    How do you add a parameter in a function to ask for credentials as mandatory.

    param(
    [parameter (Mandatory=$True)]
    [string]$ComputerName

    [parameter()]
    get-credential

    )

    I want to use the get-credential

    #34504
    Profile photo of Justin King
    Justin King
    Participant

    So technically get-credentials is already a function, so making it a parameter in your own function isn't going to work so well.

    Instead you define a parameter as the type "pscredentials" so you can use your function _with_ get-credentials. It will behave in a more predictable manner for others instead of calling "get-credentials" in your function. Example:

    param (
        [Parameter(Mandatory=$true)][PSCredential]$Credentials
        )
    

    Now you have a mandatory parameter that ONLY accepts proper credentials.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.