#InvalidOperation: (:) [], RuntimeException InvokeMethodOnNull
76 messages · Page 1 of 1 (latest)
add the full error message to your post please
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."
is that the only error? Or just the last?
and if it's just the last, what's the first?
It's the same error repeated a bunch of times
yep, but different lines each time, right?
Yep
you need the very first error
K give me a moment
that one will likely be the one that's different
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 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
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
It is
you should absolutely consider changing it
you've just shared it with anyone who happens to visit here
That account does nothing but I'll tell my boss
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
In an attempt to isolate the error. I've replaced the password string above.
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?
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
Oh no
it's the risk with scripts like this that heavily interact with MS services. They require ongoing updates as MS change things
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?
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
Damn
I'm kind of surprised it's not all using the Sharepoint PNP module, but that perhaps speaks to it's age?
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
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
that's an error in your paste, you've perhaps pasted twice?
Oh the password hehe
yeah, didn't want to propagate it 😄 Even permission to look is something to avoid
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 😅
After a couple fixes I reduced the number of errors from a thousand to 2
that's fine progress!
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
ah ambiguous parameter set name?
what's the -a for here?
Connect-PnPOnline -a -Url $AdminCenterURL -Credentials $credencial
^ This one
It´s an s
it's an a in the error message?
there isn't a -s parameter
But with the s is the same error
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
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
so if you've moved everything else the PNP module you'll have to find out what does that part
I think you want to lose that part and use this command instead:
https://pnp.github.io/powershell/cmdlets/Set-PnPUserProfileProperty.html
PnP PowerShell is an open source, community driven, PowerShell Module designed to work with Microsoft 365.
I'll try that plus some other fixes I've seen