Get-CredentialInfo cmdlet request
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
Steps to reproduce
Hi,
I was following the this article in order to register an Azure artifact reposistory. It specifically mentions: You can also use with the -Credential parameter.
I used the following snippet to try the register the PsResource:
import-module Microsoft.PowerShell.PSResourceGet -force
$Credential = Get-Credential -UserName "My@Email.com" -Message "Enter your ADO credentials" #generated the PAT as described in the article
$FriendlyName = "MyFriendlyName"
$ProjectName = "MyProjectName"
Register-PSResourceRepository -Name $FriendlyName -Uri "https://pkgs.dev.azure.com/$($ProjectName)/_packaging/$($ProjectName)/nuget/v3/index.json" -Credential $Credential
But I get the following error:
Cannot bind parameter 'CredentialInfo'. Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type
| "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
I guess this is a
Expected behavior
It should register the repository
Actual behavior
Cannot bind parameter 'CredentialInfo'. Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type
| "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
Error details
Exception :
Type : System.Management.Automation.ParameterBindingException
Message : Cannot bind parameter 'CredentialInfo'. Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
ParameterName : CredentialInfo
ParameterType : Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo
TypeSpecified : psobject
ErrorId : CannotConvertArgumentNoMessage
Line : 1
Offset : 166
CommandInvocation :
MyCommand : Register-PSResourceRepository
BoundParameters :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys :
Length : 4
Length : 3
Values :
Length : 13
Length : 93
SyncRoot :
Comparer : System.OrdinalIgnoreCaseComparer
Count : 2
Keys : …
Values : …
SyncRoot : …
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 26
Line : Register-PSResourceRepository -Name "FeedDistrict2" -Uri "https://pkgs.dev.azure.com/DigitalDistrict01/_packaging/DigitalDistrict01/nuget/v3/index.json" -Credential $Credential
PositionMessage : At line:1 char:1
+ Register-PSResourceRepository -Name "FeedDistrict2" -Uri "https://pkg …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Register-PSResourceRepository
PipelineLength : 1
PipelinePosition : 1
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Cannot bind parameter 'CredentialInfo'. Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
HResult : -2146233087
CategoryInfo : InvalidArgument: (:) [Register-PSResourceRepository], ParentContainsErrorRecordException
FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository
InvocationInfo :
MyCommand : Register-PSResourceRepository
ScriptLineNumber : 1
OffsetInLine : 166
HistoryId : 26
Line : Register-PSResourceRepository -Name "FeedDistrict2" -Uri "https://pkgs.dev.azure.com/DigitalDistrict01/_packaging/DigitalDistrict01/nuget/v3/index.json" -Credential $Credential
PositionMessage : At line:1 char:166
+ … kaging/DigitalDistrict01/nuget/v3/index.json" -Credential $Credential
+ ~~~~~~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
TargetSite :
Name : CoerceTypeAsNeeded
DeclaringType : System.Management.Automation.ParameterBinderBase, System.Management.Automation, Version=7.3.4.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Data : System.Collections.ListDictionaryInternal
InnerException :
Type : System.Management.Automation.PSInvalidCastException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
HResult : -2146233087
CategoryInfo : InvalidArgument: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : ConvertToFinalInvalidCastException
TargetSite :
Name : ThrowInvalidCastException
DeclaringType : System.Management.Automation.LanguagePrimitives
MemberType : Method
Module : System.Management.Automation.dll
Message : Cannot convert the "System.Management.Automation.PSCredential" value of type "System.Management.Automation.PSCredential" to type "Microsoft.PowerShell.PSResourceGet.UtilClasses.PSCredentialInfo".
Source : System.Management.Automation
HResult : -2147467262
StackTrace :
at System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type resultType)
at System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at System.Management.Automation.LanguagePrimitives.ConversionData`1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable)
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindNamedParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter)
at System.Management.Automation.ParameterBinderController.BindNamedParameters(UInt32 parameterSets, Collection`1 arguments)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo : InvalidArgument: (:) [Register-PSResourceRepository], ParameterBindingException
FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.PSResourceGet.Cmdlets.RegisterPSResourceRepository
InvocationInfo :
MyCommand : Register-PSResourceRepository
ScriptLineNumber : 1
OffsetInLine : 166
HistoryId : 26
Line : Register-PSResourceRepository -Name "FeedDistrict2" -Uri "https://pkgs.dev.azure.com/DigitalDistrict01/_packaging/DigitalDistrict01/nuget/v3/index.json" -Credential $Credential
PositionMessage : At line:1 char:166
+ … kaging/DigitalDistrict01/nuget/v3/index.json" -Credential $Credential
+ ~~~~~~~~~~~
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Environment data
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Binary 0.5.22 beta22 Microsoft.PowerShell.PSResourceGet {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}
Name Value
---- -----
PSVersion 7.3.4
PSEdition Core
GitCommitId 7.3.4
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created 3 months ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Get-Credential - PowerShell Command - PDQ
The Get-Credential cmdlet creates a credential object for a specified user name and password. You can use the credential object in security operations....
Read more >Using the PowerShell Get-Credential Cmdlet and all things ...
Learn PowerShell Get-Credential Cmdlet and its use in managing credentials. Check out other things about credentials in this post.
Read more >Get-Credential - PowerShell
Get a security credential object based on a user name and password. ... This is the type that most cmdlets require for specifying...
Read more >How To Manage Credentials in PowerShell
Use the Get-Credential Cmdlet ... One technique for managing PowerShell credentials is to simply make the script prompt users for a password. This ......
Read more >Is there another way to ask for credentials in Powershell ...
My Powershell Script asks for credentials using the following syntax, and it works all right: $credentials = (Get-Credential -Message "Enter ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @alerickson
It was very clear to me that a PsCredentialInfo instance was requested. What surprised me, is the fact that up until now, is that the -Credential has been used on so many different cmdlets, and it standardly asks for an object of type pscredential.
In this case, t_o me that actually felt like a bug_, as I was actually expecting the the parameter -credential to expect a pscredential NOT a PscredentialInfo
Just for completness, I add the extract to the article released on the powershell blog not so long ago:
to me, how it is written there, it sounds like you can either use the persistance feature OR use the (good old) -credential parameter.
In other terms, IF you don’t wan’t to use the credential persistence feautre, you don’t have to. But in this case, it doesn’t work I would say.
This would make sense, as it would follow the standard that has been in place since the beginning of powershell. It would become quite a mess and very confusing for the users if suddently we would have official cmdlets that would accept a PsCredential object, and others that would accept PsCredentialInfo.
I feel like the intention of -Credential was not to be able to pass a PsCredentialInfo, but that it was for (the good old) PsCredential type. (which would feel completley logic to me).
may be the good choise will be renaming
-Credential
to-CredentialInfo
to show that they are different types