Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Check if ListItem exist using PNP PowerShell.

$
0
0

Hi All,

I am working on pnp powershell to update a Master List on SPO based on csv file. 

Some of the  items on the csv file already exist  in the list. 

If the Item exist already  skip and update new items.

Import-Csv -path  "C:\contract.csv" | ForEach-Object {  

#get the titel 
    $Title = $_.Title  
    $contractNumber = $_.ContractNumber  
    $BDNumber =$_.BDNum
    
    $listItems= (Get-PnPListItem -List MainList -Fields "Title","BDNumber","GUID") 
  foreach($listItem in $listItems){  
  #check if item exsit or not
     if($listItem.Title -eq $Title){
     Write-Host "Item exsit" -ForegroundColor Red
      }
   else {

    Write-Host "Title" : $listItem["Title"]  -ForegroundColor Green
    Write-Host "Gettint Item from CSV": $Title, $URL,$BDNumber
    $itemVal = @{"Title" = $Title;"contractNumber; "= $contractNumber; "BDNumber"=$BDNumber;}  
    Add-PnPListItem -List MainList  -Values $itemVal
    Write-Host "---------------------------"  

   }
} 
    
}


Abenet


Viewing all articles
Browse latest Browse all 7589

Trending Articles