Skip to main content

Posts

Showing posts from December, 2014

Copy List Item to other list in SharePoint using Powershell

#  In the below code, there are five custom variables ## $srcListSiteUrl : Site url where the source list is present ## $SourceListName : Name of the source list ## $dstListSiteUrl : Site url where the destination list is present (In the above code both lists are in the same site) ## $DestinationListName : Name of the destination list ## $keyColumnInternalName : Column name with which we have to check whether to insert or update. ## Note, in the above example $keyColumnInternalName value is ‘Title’. It is Text type. So, the CAML query variable $camlQuery is constructed in that way. ## If you have different data type column which you want to use as a reference column, you have to change the variable accordingly as the column type. ### Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue     try     {     $srcListSiteUrl = "http://contoso...

Delete a List Item from a SiteCollection in SharePoint using Powershell

$site = Get-SPSite "http://contoso:1212/mysites/" $web = $site.rootweb $list = $web.Lists["Market"] $caml="" #optional filter #<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">Form</Value></Eq></Where>" $query=new-object Microsoft.SharePoint.SPQuery $query.ViewAttributes = "Scope='Recursive'" $query.Query=$caml $items=$list.GetItems($query) Write-Host $items.Count $items | % { $list.GetItemById($_.Id).Delete() } $web.Dispose() $site.Dispose()

Import List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  $csvVariable= Import-CSV -path "http://sp2010.contoso.com/finance/" # Destination site collection $WebURL = "http://sp2010.contoso.com/sites/Utility/"  # Destination list name $listName = "Inventory"  #Get the SPWeb object and save it to a variable $web = Get-SPWeb -identity $WebURL  #Get the SPList object to retrieve the list $list = $web.Lists[$listName]  #Get all items in this list and save them to a variable  $items = $list.items        #loop through csv file foreach($row in $csvVariable) {     $updated = 0     #loop through SharePoint list     foreach($item in $items)     {         if($item["ID #"] -eq $row."ID #")              {                  $updated++          ...

Export List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue     #Get the target site collection  $web = Get-SPWeb -identity "http://sp2010.contoso.com/finance/"    #Get the Target List  $list = $web.Lists["Purchase"]     #Array to Hold Result - PSObjects  $ListItemCollection = @()      #Get All List items where Products is Stationary  $list.Items |  Where-Object { $_["Products"] -eq "Stationary"} | foreach {   $ExportItem = New-Object PSObject    $ExportItem | Add-Member -MemberType NoteProperty -name "Products" -value $_["Products"]   $ExportItem | Add-Member -MemberType NoteProperty -Name "Quantity" -value $_["Quantity"]   $ExportItem | Add-Member -MemberType NoteProperty -name "Vendor" -value $_["Vendor"]   $ExportItem | Add-Member -MemberType NoteProperty -name "ID #" -value $_["ID"]  $ExportI...