Closed pcgeek86 closed 5 years ago
Could you provide a stack trace for the error?
I think a nice way to provide all available detail is to use Resolve-Error
as described here https://devblogs.microsoft.com/powershell/resolve-error/
Sure, let me know how this looks. @matteo-prosperi
PSMessageDetails :
Exception : System.NullReferenceException: Object reference not set to an instance of an object.
at
System.Management.Automation.CmdletParameterBinderController.GetDefaultParameterValuePairsHelper(String
cmdletName, String paramName, Object paramValue, IDictionary`2 bindableParameters, IDictionary`2
bindableAlias, Dictionary`2 result, HashSet`1 parametersToRemove)
at System.Management.Automation.CmdletParameterBinderController.GetDefaultParameterValuePairs(Boolean
needToGetAlias)
at System.Management.Automation.CmdletParameterBinderController.ApplyDefaultParameterBinding(String
bindingStage, Boolean isDynamic)
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)
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)
TargetObject :
CategoryInfo : OperationStopped: (:) [], NullReferenceException
FullyQualifiedErrorId : System.NullReferenceException
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
MyCommand :
BoundParameters : {}
UnboundArguments : {}
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : -1
ScriptName :
Line : Set-AWSCredential -ProfileName MyProfileName
PositionMessage : At line:1 char:1
+ Set-AWSCredential -ProfileName MyProfileName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot :
PSCommandPath :
InvocationName :
PipelineLength : 0
PipelinePosition : 0
ExpectingInput : False
CommandOrigin : Internal
DisplayScriptPosition :
00000000000000000000000000000000000000000000000000000000000000000000000000000000
Message : Object reference not set to an instance of an object.
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException :
TargetSite : Void GetDefaultParameterValuePairsHelper(System.String, System.String, System.Object, System.Collections.Generic
.IDictionary`2[System.String,System.Management.Automation.MergedCompiledCommandParameter], System.Collections.Ge
neric.IDictionary`2[System.String,System.Management.Automation.MergedCompiledCommandParameter], System.Collectio
ns.Generic.Dictionary`2[System.Management.Automation.MergedCompiledCommandParameter,System.Object],
System.Collections.Generic.HashSet`1[System.Management.Automation.MergedCompiledCommandParameter])
StackTrace : at System.Management.Automation.CmdletParameterBinderController.GetDefaultParameterValuePairsHelper(String
cmdletName, String paramName, Object paramValue, IDictionary`2 bindableParameters, IDictionary`2 bindableAlias,
Dictionary`2 result, HashSet`1 parametersToRemove)
at System.Management.Automation.CmdletParameterBinderController.GetDefaultParameterValuePairs(Boolean
needToGetAlias)
at System.Management.Automation.CmdletParameterBinderController.ApplyDefaultParameterBinding(String
bindingStage, Boolean isDynamic)
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)
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)
HelpLink :
Source : System.Management.Automation
HResult : -2147467261
That is unexpected. The error trace shows the error happening in internal PowerShell code (System.Management.Automation
).
I have also tested this with 3.3.509.0
on Linux and I am not getting this error while trying either an existing or unexisting profile.
Could you trace the command and send me the trace?
Trace-Command -Name ParameterBinding -Expression { Set-AWSCredential -ProfileName foo } -PSHost
It turns out this was completely my fault. I had configured a PowerShell profile script that uses $PSDefaultParameterValues
to set -AccessKey
, -SecretKey
and -SessionToken
on all AWS commands. Normally I'm against using this, but for a recent need, I chose to give it a try.
Once I tried the Set-AWSCredential -Profile foo
command from a pwsh -NoProfile
session, it works just fine. Sorry for the noise.
Expected Behavior
The
Set-AWSCredential -ProfileName MyMfaSessionToken
command should simply set the "default" AWS credentials profile for the current PowerShell session, according to the documentation.https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html
Current Behavior
I'm receiving an error message.
Possible Solution
Not sure.
Steps to Reproduce (for bugs)
Context
I have my "default" AWS credentials profile configured with my Access Key ID and Secret Key. These credentials give me access to call
Get-STSSessionToken
, which I use to retrieve an AWS Session Token via Multi-Factor Authentication (MFA).I'm using the
PsIni
module to write the AWS Session Token back to my AWS credentials file, under a profile name calledMyMfaSessionToken
.Once configured, I want to set this profile as the "default" AWS credentials profile for my PowerShell session. That is when I call
Set-AWSCredential
and encounter the error message posted above.Your Environment