vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
759 stars 604 forks source link

Improve Error Handling to display the server error of New-SsoPersonUsers; VMware.vSphere.SsoAdmin Module #410

Closed nacho-osete closed 3 years ago

nacho-osete commented 3 years ago

After using the VMware.vSphere.SsoAdmin Module for a while, I found that New-SsoPersonUser throws a method invocation exception related to the CreateLocalUser function at the VMware.vSphere.SsoAdmin Module. Here's the output for further reference:

> New-SsoPersonUser -User testuser -Password '****' -EmailAddress '*some-email*' -FirstName 'Test' -LastName 'User'

New-SsoPersonUser : Excepción al llamar a "CreateLocalUser" con los argumentos "6": "Se han producido uno o varios errores."
En línea: 1 Carácter: 1
+ New-SsoPersonUser -User testuser -Password '*****' -EmailAddre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-SsoPersonUser], MethodInvocationException
    + FullyQualifiedErrorId : AggregateException,New-SsoPersonUser

> $Error

En C:\***\VMware.vSphere.SsoAdmin\VMware.vSphere.SsoAdmin.psm1: 327 Carácter: 10
+          $connection.Client.CreateLocalUser(
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : AggregateException
dmilov commented 3 years ago

Can you paste all the detailes of the error please

$error[0] | select *
$error[0].Exception | select *
nacho-osete commented 3 years ago

Here's the output, thank you @dmilov

ErrorRecord                 : Excepción al llamar a "CreateLocalUser" con los argumentos "6": "Se han producido uno o varios errores."
WasThrownFromThrowStatement : False
Message                     : Excepción al llamar a "CreateLocalUser" con los argumentos "6": "Se han producido uno o varios errores."
Data                        : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException              : System.Management.Automation.MethodInvocationException: Excepción al llamar a "CreateLocalUser" con los argumentos "6": "Se han producido uno o varios errores." --->
                              System.AggregateException: Se han producido uno o varios errores. ---> 
                              System.ServiceModel.FaultException`1[VMware.vSphere.SsoAdminClient.SsoAdminServiceReferencer.SsoFaultInvalidPrincipalFault]: The specified principal (lamw) is invalid.
                              Caused by: Another user or group already exists with the same name: accountName=TestUser, principal=testuser@vsphere.local
                                 en System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
                                 en System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
                                 en System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass7_0`1.<CreateGenericTask>b__0(IAsyncResult asyncResult)
                                 en System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
                                 --- Fin del seguimiento de la pila de la excepción interna ---
                                 en System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
                                 en VMware.vSphere.SsoAdminClient.SsoAdminClient.CreateLocalUser(String userName, String password, String description, String emailAddress, String firstName, String lastName)  
                                 en CallSite.Target(Closure , CallSite , Object , Object , Object , Object , Object , Object , Object )
                                 --- Fin del seguimiento de la pila de la excepción interna ---
                                 en System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                                 en System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                                 en System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                                 en System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                                 en System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
                                 en System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
                                 en System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
                                 en System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
                                 en System.Management.Automation.CommandProcessor.ProcessRecord()
TargetSite                  : System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject] Invoke(System.Collections.IEnumerable)
StackTrace                  :    en System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
                                 en System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
                                 en System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
                                 en System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
                                 en System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
                                 en System.Management.Automation.PowerShell.Invoke[T](IEnumerable input, PSInvocationSettings settings)
                                 en System.Threading.Tasks.Task`1.InnerInvoke()
                                 en System.Threading.Tasks.Task.Execute()
                              --- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
                                 en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                                 en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                                 en Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.<ExecuteCommandAsync>d__89`1.MoveNext()
                              --- Fin del seguimiento de la pila de la ubicación anterior donde se produjo la excepción ---
                                 en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                                 en Microsoft.PowerShell.EditorServices.Services.PowerShellContextService.<ExecuteCommandAsync>d__89`1.MoveNext()
HelpLink                    : 
Source                      : System.Management.Automation
HResult                     : -2146233087
dmilov commented 3 years ago

The server threw the following error Another user or group already exists with the same name Updating the issue to improve error handling in the module

nacho-osete commented 3 years ago

Thank you @dmilov, I will cross-check my sso user creation script with the Get-SsoPersonUser function in advance. I believe we may close the issue in any case.

nacho-osete commented 3 years ago

(Proceeding for closure)