0

I have in my excel one column name Country with Multiple values like This enter image description here I want to read the values from excel and update the choice field in sharepoint through powershell. Below code Works fine and it updates the field in sharepoint view. However when i edit the item the multi choice field is not selected . Below is the screen shot for the sameenter image description here

Code is like Below

$sInputFile="C:\PopulateList\New folder\Countries.csv"
 #Adding the Client OM Assemblies        
        $sCSOMRuntimePath=$sCSOMPath +  "\Microsoft.SharePoint.Client.Runtime.dll"        
        $sCSOMPath=$sCSOMPath +  "\Microsoft.SharePoint.Client.dll"             
        Add-Type -Path $sCSOMPath         
        Add-Type -Path $sCSOMRuntimePath       

        #SPO Client Object Model Context
        $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteUrl)
        $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUserName, $sPassword)  
        $spoCtx.Credentials = $spoCredentials
        $spoList = $spoCtx.Web.Lists.GetByTitle($sListName)
        $spoCtx.Load($spoList)  

        $tblItems = Import-CSV $sInputFile  
        foreach ($sItem in $tblItems) 
        {

         try{

            $spoListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
            $spoListItem=$spoList.AddItem($spoListItemCreationInformation)


            $Countries=$sItem.Country.ToString();

            #when i Write-host i get countries like this "U.K,Australia" for the first Record


            $spoListItem["Country"]=$Countries ;

            $spoListItem.Update()
            $spoCtx.ExecuteQuery() 

            }

            catch{
            write-host "$($_.Exception.Message)" -foregroundcolor red

            }


        }
  • Is this a choice field? Try delimiting the values you’re writing with ;# so you write a string like this: ;#U.K.;#Australia;# – sasfrog May 18 '18 at 21:50
  • Yes, choice field with multi values selection.If I take an array an hard code the vales like this countr ,=@( "U.k", AUSTRALIA") it works. But from an excel column how can I format likethis – santosh kondapalli May 19 '18 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.