#InvalidOperation: (:) [], RuntimeException InvokeMethodOnNull

76 messages · Page 1 of 1 (latest)

steel magnet
#

So there's this script made by the person who was in my job before me but there's no way to contact him and I'd never used PowerShell before, to make this fast the script works until the part where it updates the user data. Any help is appreciated and please let me know if you need more stuff or transalating...

#

InvalidOperation: (:) [], RuntimeException InvokeMethodOnNull

dire nova
#

add the full error message to your post please

steel magnet
#

Right right give me a second

#

No se puede llamar a un método en una expresión con valor NULL.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 115 Carácter: 13

  •         $Ctx.ExecuteQuery()
    
  •         ~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull
#

It says in english "You cannot call a method on an expression with a NULL value."

dire nova
#

is that the only error? Or just the last?

#

and if it's just the last, what's the first?

steel magnet
#

It's the same error repeated a bunch of times

dire nova
#

yep, but different lines each time, right?

steel magnet
#

Yep

dire nova
#

you need the very first error

steel magnet
#

K give me a moment

dire nova
#

that one will likely be the one that's different

steel magnet
#

No se puede llamar a un método en una expresión con valor NULL.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 101 Carácter: 13

  •         $User = $Ctx.web.EnsureUser($membership)
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull
dire nova
#

that one is still null, this ultimately uses these: ```ps
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL)
$Ctx.Credentials = $CredencialesSPO

#

but if creation of that object fails, if you can't connect to sharepoint, then the whole thing will come crashing down

steel magnet
#

Makes sense

#

But where can I see if it connects?

#

Establecer los valores para Carolina Ortega Torres...
Actualizando propiedades...
La ruta de la foto es C:\Carga de fotos intranet Gentor\usuarios\gentor.com\cortega.jpg
Cargando foto...
ADVERTENCIA: El cmdlet Set-UserPhoto está en desuso en PowerShell de Exchange Online. Para obtener más información, consulte 'https://
go.microsoft.com/fwlink/p/?linkid=2249705'.
ADVERTENCIA: El cmdlet Set-UserPhoto está en desuso en PowerShell de Exchange Online. Para obtener más información, consulte 'https://
go.microsoft.com/fwlink/p/?linkid=2249705'.
Actualizando perfil de usuario...
No se puede llamar a un método en una expresión con valor NULL.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 101 Carácter: 13

  •         $User = $Ctx.web.EnsureUser($membership)
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull
#

That's the whole thing that it prints up until the first error

dire nova
#

um you have a password in your script

#

it's not real, right?

steel magnet
#

It is

dire nova
#

you should absolutely consider changing it

#

you've just shared it with anyone who happens to visit here

steel magnet
#

That account does nothing but I'll tell my boss

dire nova
#

after that, you should try ```ps
$inquilino = "gentor"
$AdminCenterURL="https://$($inquilino)-admin.sharepoint.com"

$usuario="[email protected]"
$contraseña= ConvertTo-SecureString -String "abc" -AsPlainText -Force

$CredencialesSPO = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($usuario, $contraseña)

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL)
$Ctx.Credentials = $CredencialesSPO

$Ctx.web

In an attempt to isolate the error. I've replaced the password string above.
steel magnet
#

Let me try it

#

Oh new error this time

#

Connect-MsolService : El término 'Connect-MsolService' no se reconoce como nombre de un cmdlet, función, archivo de script o
programa ejecutable. Compruebe si escribió correctamente el nombre o, si incluyó una ruta de acceso, compruebe que dicha ruta es
correcta e inténtelo de nuevo.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 51 Carácter: 1

  • Connect-MsolService -Credential ($credencial)
  •   + CategoryInfo          : ObjectNotFound: (Connect-MsolService:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
#

It says Connect-MsolService isn't recognized as a cmdlet or command, I'm assuming that's where the SharePoint connection error is right?

dire nova
#

Azure AD, but you're heading a long way into deprecated command territory now. MS have been moving everything over to Graph which is potentially a serious problem for this script

steel magnet
#

Oh no

dire nova
#

it's the risk with scripts like this that heavily interact with MS services. They require ongoing updates as MS change things

steel magnet
#

A coworker tells me all of that is going down this year which makes this script kinda obsolete

#

Is there a quick fix until that happens?

dire nova
#

depends what the actual problem is, but if it's the sharepoint part I'd have to duck out. I have no expertise there, I'd only be able to get you as far as an error message

steel magnet
#

Damn

dire nova
#

I'm kind of surprised it's not all using the Sharepoint PNP module, but that perhaps speaks to it's age?

steel magnet
#

Yup

#

So it's a dead end

dire nova
#

it potentially requires work. The fragment above was missing the assemblies, but this is the part intended to see if you can connect and get to $Ctx.web. The error you have is basically a "$Ctx doesn't have a value" problem.

That, in turn, suggests the attempt to connect is failing completely

#

this is the updated fragment: ```ps
Add-Type -AssemblyName Microsoft.SharePoint.Client
Add-Type -AssemblyName Microsoft.SharePoint.Client.runtime
Add-Type -AssemblyName Microsoft.SharePoint.Client.UserProfiles

$inquilino = "gentor"
$AdminCenterURL="https://$($inquilino)-admin.sharepoint.com"

$usuario="[email protected]"
$contraseña= ConvertTo-SecureString -String "abc" -AsPlainText -Force

$CredencialesSPO = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($usuario, $contraseña)

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL)
$Ctx.Credentials = $CredencialesSPO

$Ctx.web

steel magnet
#

Let's see

#

En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 16 Carácter: 12

  • $Ctx.webAdd-Type -AssemblyName Microsoft.SharePoint.Client
  •        ~~~~~
    

Token '-Type' inesperado en la expresión o la instrucción.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 16 Carácter: 18

  • $Ctx.webAdd-Type -AssemblyName Microsoft.SharePoint.Client
  •              ~~~~~~~~~~~~~
    

Token '-AssemblyName' inesperado en la expresión o la instrucción.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken

dire nova
#

that's an error in your paste, you've perhaps pasted twice?

steel magnet
#

Oh the password hehe

dire nova
#

yeah, didn't want to propagate it 😄 Even permission to look is something to avoid

steel magnet
#

No worries as I said that account is only to update the pictures and birthdays of my fellow coworkers so it wouldn't be the end of the world 😅

steel magnet
#

After a couple fixes I reduced the number of errors from a thousand to 2

dire nova
#

that's fine progress!

steel magnet
#

Connect-PnPOnline : No se puede procesar el parámetro porque el nombre de parámetro 'a' es ambiguo. Las posibles coincidencias son:
-AppId -AppSecret -AuthenticationMode -AzureEnvironment -AADDomain -AccessToken.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 56 Carácter: 20

  • Connect-PnPOnline -a -Url $AdminCenterURL -Credentials $credencial
  •                ~~
    
    • CategoryInfo : InvalidArgument: (:) [Connect-PnPOnline], ParameterBindingException
    • FullyQualifiedErrorId : AmbiguousParameter,PnP.PowerShell.Commands.Base.ConnectOnline

New-Object : No se encuentra el tipo [Microsoft.SharePoint.Client.UserProfiles.PeopleManager]. Compruebe que está cargado el
ensamblado que lo contiene.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 62 Carácter: 18

  • ... leManager = New-Object Microsoft.SharePoint.Client.UserProfiles.Peopl ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
#

Except idk what's this

dire nova
#

ah ambiguous parameter set name?

steel magnet
#

Yes

#

It's -s in the script

dire nova
#

what's the -a for here?

Connect-PnPOnline  -a -Url $AdminCenterURL -Credentials $credencial
                    ^ This one
steel magnet
#

It´s an s

dire nova
#

it's an a in the error message?

steel magnet
#

Whoa

#

Oh right maybe it's from the previous test

dire nova
#

there isn't a -s parameter

steel magnet
#

But with the s is the same error

dire nova
#

yeah there's nothing that'll obviously use -s unless it's hitting a parameter alias

#

no listed aliases or parameters start with s, so I'd expect it to be telling you the parameter doesn't exist

steel magnet
#

I see

#

Can I remove it without breaking the whole thing?

#

Apparently I can

#

That error is gone

#

So there's just one left

#

New-Object : No se encuentra el tipo [Microsoft.SharePoint.Client.UserProfiles.PeopleManager]. Compruebe que está cargado el
ensamblado que lo contiene.
En C:\Carga de fotos intranet Gentor\Carga-FotosGentor.ps1: 62 Carácter: 18

  • ... leManager = New-Object Microsoft.SharePoint.Client.UserProfiles.Peopl ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
dire nova
#

so if you've moved everything else the PNP module you'll have to find out what does that part

steel magnet
#

I'll try that plus some other fixes I've seen