Azure function - Powershell code working on local but not on azure

Dubreuil, Jean-Baptiste 1 Reputation point
2020-08-17T13:43:26.667+00:00

Hello I'm facing strange issue, my script is working perfectly on my local laptop but when I try to execute it from Azure function I'm getting an exception.

Goal of this script is to update SharePoint item from external API. When I assigned a value to my sharepoint item metadata with this code :

$itemSP[$mapping.SP]=$value

I'm getting this exception on every metatada assignement (of any type) :

Cannot convert value "Title" to type "System.Int32". Error: "Input string was not in a correct format." at Update-Items, <No file>: line 94 at run.ps1: line 180 + + + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidCastFromStringToInteger,run.ps1

There is any reason ?

Thanks for your assist.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,965 questions
{count} votes

2 answers

Sort by: Most helpful
  1. sadomovalex 3,631 Reputation points
    2020-08-17T14:42:29.41+00:00

    hi, do you use this script against Sharepoint Online or on-prem? How exactly do you import Sharepoint CSOM into PowerShell?
    Try to check what exact type $itemSP variable has:

    Write-Host $itemSP.GetType().FullName
    

  2. MayankBargali-MSFT 70,406 Reputation points
    2020-08-18T07:55:34.027+00:00

    Hi @Dubreuil, Jean-Baptiste

    Looking into the error message it says that value "Title" cannot be converted to System.Int32 i.e. looks like the value is expected as an integer value.
    Can you please verify what code you have written/executing in line no 94 in the run.ps1 file and verify if you are passing the integer value or not for that statement.

    If the expected value is a string then you need to update your code on line 94. If the value can be empty that in your code you need to first verify where the value is null or empty before typecasting it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.