0

Until last Friday I was using the following powershell script to manipulate lists on Sharepoint Online using CSOM with no problems.

$spOcredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($spOuser, $secpasswd)
$spOctx = New-Object Microsoft.SharePoint.Client.ClientContext($spOSiteURL)
$spOctx.Credentials = $spOcredentials

$spOList = $spOctx.Web.Lists.GetByTitle($spOListName)
$spOctx.Load($spOList)
$spOctx.Load($spOList.Fields)
$spOctx.ExecuteQuery()

The script is based on this article

Yesterday I found out that the script stopped working and the call to ExecuteQuery() returns an error:

Exception calling "ExecuteQuery" with "0" argument(s): "Input string was not in a correct format."
At C:\Develop\Kontrola sloupcu seznamu.ps1:36 char:1
+ $spOctx.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ServerException

I searched for what kind of error it is and how to prevent it, but I didn't find a relevant solution.

Today, purely by accident, I came up with a way to make the script work. When I call ExecuteQuery() twice, the first one ends up with the above error, but the second one runs fine. I'm confused by this and it certainly doesn't feel like a clean solution.

4
  • Check to see if credentials are valid. You may have a temporary credential that expired after 30 days (or similar). Or the website URI is no longer valid. Commented Jun 28, 2023 at 8:52
  • Credentials and URI are valid. This is a site I own, so I should know about the URI change. Additionally, it wouldn't explain why the first ExecuteQuery() ends up with an error and the second one on the next line runs correctly. Commented Jun 28, 2023 at 9:35
  • The credentials need to be verified by a password server. There may be a delay getting the credentials causing the error. Once the credentials are verified to code works. Commented Jun 28, 2023 at 9:48
  • Check for recent changes in the schema of the list. That said, consider using PnP.Powershell, your scripts will be easier to write (especially regarding the authentication. Commented Jul 3, 2023 at 8:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.