List Item changelog through Powershell (CSOM)

Hi!
I am trying to figure out how to get information about the historical changes made to a sharepoint list.
So far, I have come up with the below code. My goal is to get details like - the type of change, time, new value, old value, row/column names and modified by. I know this has something to do with Microsoft.Sharepoint.Client.Change but can't figure out the
logic behind it.
[Reflection.Assembly]::LoadFrom("$scriptdir\Microsoft.SharePoint.Client.dll")
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$context.RequestTimeOut = 1000 * 60 * 10;
$context.AuthenticationMode = [Microsoft.SharePoint.Client.ClientAuthenticationMode]::Default
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$context.Credentials = $credentials
$web = $context.Web
$site = $context.Site
$context.Load($web)
$context.Load($site)
$context.ExecuteQuery()
Set-Variable -Name "clientContext" -Value $context -Scope Global
Set-Variable -Name "rootSiteUrl" -Value $siteURL -Scope Global
Function Get-ListChanges {
$listName = "Tasks"
$list = $clientContext.Web.Lists.GetByTitle($listName)
$cq = new-object Microsoft.Sharepoint.Client.ChangeQuery($true,$true)
$changes = $list.GetChanges($cq)
$clientContext.Load($changes)
$clientContext.ExecuteQuery()
$changes.count
foreach ($item in $changes) {
# get data here from specific column name/old values/newvalues
Any help would be appreciated. Thank you for looking in to this.
A Tank

Hi A Tank,
You need to call the properties of change object inside that foreach loop like this:
foreach ($item in $changes) {
# get data here from specific column name/old values/newvalues
Write-Host $item.ChangeType '--' $item.Time
All the properties are listed here:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.change_members%28v=office.15%29.aspx
Best Regards,
Brij K

Similar Messages

  • Update a list item based sort order of created by column value

    HI
    using powershell script how to sort a list column before update a list  item.
    here i created a document library and uploaded some documents and update ProcessNo column based sort order of created column
    value.
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:91" $listName = "Courts"
    Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    $list = $web.Lists[$listName] 
    $items = $list.items
    Go through all items
    foreach($item in $items)
    $item["ProcessNo"] = 1
    $item.Update()
    $web.Dispose()

    Hi,
    According to your description, my understanding is that you want to sort the list items order before updating items using PowerShell.
    I suggest you can use the Sort-Object command to sort the list items.
    Here are some detailed articles for your reference:
    Better SharePoint Lists and List Items in PowerShell
    Sort-Object
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to get Metadata column values using powershell(CSOM)

    Hi,
    I am trying to get list column values using Powershell (CSOM), but I am getting for Metata data columns.
    I am getting internal value as System.Collections.Generic.Dictionary`2[System.String,System.Object] 
    Can anybody let me know how to get the values for metadata columns?
    Any help would be greatly appreciate.
    Thank you.
    AA.

    Hi
    Go through the links. It'll help.
    SharePoint 2013 Code Tips – Setting a Managed Metadata Field with the Client Object Model(CSOM and JSOM)
    Indul Hassan
    Microsoft Community Contributor
    http://www.indulhassan.com
    You Snooze.. You Lose !!

  • Deleting a contact list item through Powershell in sharepoint 2010 synced with outlook 2010, does not delete the item from outlook.

    hi All,
    I have a requirement for updating the contact list from CSV file and updating/ adding and  deleting the changes in the SharePoint list using PowerShell script. List is also synced with outlook.
    The problem arises, when we delete an item from the list using PS, the item (which was earlier synced with outlook) is not getting deleted from outlook.
    Strange behavior : when we perform the same deletion operation manually from the SharePoint UI, every thing works fine as required.
    Please refer the below PS
    #Adding the records from SharePoint not in CSV file
    if($flag -ne 1)
    Get-Member -InputObject $csvRow -MemberType NoteProperty | ForEach-Object {
    $property = $_.Name
    $newItem.set_Item($property, $csvRow.$property)
    $newItem.Update()
    #Deleting the records from SharePoint not in CSV file
    CreatePSLog "Deleting the records from SharePoint not in CSV file"
    foreach($itm in $List.items)
    $del = 0
    $items | ForEach-Object {
    if($itm["SAP Ansprechpartnernr"] -eq $_."SAP Ansprechpartnernr")
    $del++;
    if(!$del)
    $List.GetItemById($itm.Id).Delete()
    $List.Update();
    $Web.Update();
    many thanks in advance, Please suggest as I am completly stuck on this :(
    Regards, Arun kumar

    Hi Kumar,
    Please remove the codeline $List.Update();, then run your code again, it works for me.
    You may need to firstly delete the synced contacts list within Outlook to remove those undeleted accounts, then re-connect the SharePoint contacts list to outlook, then run your modified Powershell code.
    Thanks
    Daniel Yang
    TechNet Community Support

  • One line Powershell to delete all list items?

    Is it possible to have one line powershell to delete all items in a list (no folders)?
    I tried this one from
    http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/de844268-6bb5-4510-9c83-bbca24cf278f,
    $list.get_items() | where { $_.column name with spaces -like '3*' } | % { $_.Delete() }.
    In my case, I remove the middle part: $list.get_items() | % { $_.Delete() }
    I got one item removed with the exception:
    An error occurred while enumerating through a collection: Collection was modifi
    ed; enumeration operation may not execute..
    At line:1 char:1
    +  <<<< $list.Get_Items() | % {$_.Delete()}
        + CategoryInfo          : InvalidOperation: (Microsoft.Share...on+SPEnumer
       ator:SPEnumerator) [], RuntimeException
        + FullyQualifiedErrorId : BadEnumeration
    Seems I am missing some here - I am running Powershell through SharePoint 2010 Management Shell as Administrator.

    this happens because after you delete the first item, the original collection is modified.
    You can do a simple while to delete all items:
    while($list.Items.Count -gt 0){$list.Items.Delete(0)}
    Hope this could help.

  • Unable to Read Calendar List Items through CAML

    Hi All,
    * I have created two columns in calendar one Year and other Month.When new event is added in calendar through (Item Added) event receiver I am setting the values to this columns as Name of Month to(February) and Year as(2014)  .So that I can fetch the
    data easily based on month and year
    * Through this Columns Secondly when I try to fetch the data to count number of items of particular month and year using caml query I am getting error as below .
    "Error:One or more field types are not installed properly. Go to the list settings page to delete these fields."
    *My below caml code is working fine if i applied to custom list,But not to calendar.Can any one help me for what reason I am unable to fetch data
    Code
     string year="2014";
     string month="February";
     SPSite mysite = SPContext.Current.Site;
     SPWeb myweb = mysite.OpenWeb();
    SPList mylist = myweb.Lists["Calendar"];
     SPQuery myquery = new SPQuery();
      myquery.Query = @"<Where>
                                          <And>
                                           <Eq>
                                             <FieldRef Name='Year'/>
                                             <Value Type='Text'>" + year + @"</Value>
                                          </Eq>
                                          <Eq>
                                             <FieldRef Name='Month' />
                                             <Value Type='Text'>" + month + @"</Value>
                                          </Eq>
                                         </And>
                                      </Where>";
     SPListItemCollection totaltiems = mylist.GetItems(myquery);
      Label1.Text= "Total Number of Items is "+" "+totaltiems.Count.ToString();
    Thanks, Quality Communication Provides Quality Work. http://siddiq-sharepoint2010.blogspot.in/ Siddiqali Mohammad .

    Hi,
    According to your post, my understanding is that you got an error when read calendar list items using CAML.
    I created two single line of text columns in the Calendar( Year and Month), then add items in the Calendar to check with your code. The CAML query worked well as below.
    string year = "2014";
    string month = "February";
    using (SPSite oSiteCollection = new SPSite("Your site URL"))
    using (SPWeb myweb = oSiteCollection.OpenWeb())
    SPList mylist = myweb.Lists["Calendar"];
    SPQuery myquery = new SPQuery();
    myquery.Query = @"<Where> <And> <Eq> <FieldRef Name='Year'/> <Value Type='text'>" + year
    + "</Value></Eq><Eq>+ "
    + " <FieldRef Name='Month' />+ "
    + " <Value Type='text'>" + month + "</Value>+ "
    + " </Eq> </And></Where>";
    SPListItemCollection totaltiems = mylist.GetItems(myquery);
    Console.WriteLine( "Total Number of Items is " + " " + totaltiems.Count.ToString());
    Console.ReadLine();
    Which type of the two columns in your Calendar? Were they text type?
    Are you sure the field name(<FieldRef Name='Year'/>,
    <FieldRef Name='Month' />) is same as internal name?
    We should only use internal name while refrencing columns in CAML query. If you have space In you column , replace it with "_x0020_", such as
    News_x0020_Category. 
    Thanks & Regards,
    Jason 
    Jason Guo
    TechNet Community Support

  • Retrieving list items from a specific view using CSOM

    How can I query a specific view of a SharePoint List using the C# CSOM? I am dealing with SharePoint Online, so the only option is to use SharePoint.Client.
    I have done this using Javascript, and I know how to do this with SharePoint On-Premises, but I haven't found a way to do with for SharePoint online using C#.

    hi Dkhouri,
    thanks for posting your issue, you can create a specific view of a list using CSOM and C#.
    Kindly find the code snippet below fort he same.
    Code for CSOM :- 
    // Starting with ClientContext, the constructor requires a URL to the
    // server running SharePoint.
    ClientContext context = new ClientContext("http:SiteUrl");
    // Assume the web has a list named "Announcements".
    List announcementsList = context.Web.Lists.GetByTitle("Announcements");
    // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
    // so that it grabs all list items, regardless of the folder they are in.
    CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
    ListItemCollection items = announcementsList.GetItems(query);
    // Retrieve all items in the ListItemCollection from List.GetItems(Query).
    context.Load(items);
    context.ExecuteQuery();
    foreach (ListItem listItem in items)
    // We have all the list item data. For example, Title.
    label1.Text = label1.Text + ", " + listItem["Title"];
    For C# 
    public CamlQuery CreateInventoryQuery(string searchSku)
    var qry = new CamlQuery();
    qry.ViewXml =
    @"<View>
    <Query>
    <Where>
    <BeginsWith>
    <FieldRef Name='SKU' />
    <Value Type='Text'>" + searchSku + @"</Value>
    </BeginsWith>
    </Where>
    </Query>
    </View>";
    return qry;
    Also, checkout below mentioned URLs for more details
    http://www.c-sharpcorner.com/UploadFile/sagarp/sharepoint-2013-caml-query-for-item-id-with-jquery/
    http://msdn.microsoft.com/en-us/library/ff798388.aspx
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • PowerShell script to find a string of characters in office documents in Doc Libraries and List Item attachments?

    Hi there,
    For SharePoint 2010 site - Does someone have the PowerShell script to find a string of characters in Office/Word/Excel/PDF documents in document libraries or the ones attached to List Items?
    Thanks so much in advance.

    Hi,
    According to your description, my understanding is that you want to find some specific string character in list items using PowerShell Command.
    $w = Get-SPWeb "http://devmy131"
    $l = $w.GetList("http://devmy131/lists/fieldslist");
    $i = $l.Items[0]["Title"].ToString();
    if ($i -like '*document*')
    Write-Host "Title contains document character" $i;
    More information:
    PowerShell -contains -like
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • CAMl Query -CSOM - Display Modified date of list Item in a required format

    Hi All,
    I want to display last modified date of a List Item.
    I am getting the value in this format : 
    Tue Feb 25 23:06:57 PST 2014
    How ever, I want to display it as : Tuesday 25th February 2014
    Please suggest how to achieve this.
    Any informative articles, links w.r.t building such queries in CSOM (jQuery) is welcome.
    Thanks.

    I have the query : 
    function ReadListItem() {
                siteUrl = "my site Url";
                var listTitle = "NewsList";
                //Get the current client context
                var context = new SP.ClientContext(siteUrl);
                var newsList = context.get_web().get_lists().getByTitle(listTitle);
                var camlQuery = new SP.CamlQuery();         
                camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name=\'Modified\' Ascending="FALSE"/></OrderBy><RowLimit>1</RowLimit></Query></View>";')
                this.listItems = newsList.getItems(camlQuery);
                context.load(listItems);
                context.executeQueryAsync(ReadListItemSucceeded, ReadListItemFailed);
            function ReadListItemSucceeded(sender, args) {
                var itemsString = '';
                var enumerator = listItems.getEnumerator();
                while (enumerator.moveNext()) {
                    var listItem = enumerator.get_current();
                    itemsString += 'Modified On: ' + listItem.get_item('Modified');
                $("#P1").append(itemsString);
    I am able to get the Modified Date using the query
    But I need it in a specific format like : Tuesday 25th February 2014
    Please suggest

  • ECMA/CSOM script to update multiple list items

     i am trying update multiple list items using CSOM/ECMA script but it updates only first record. can help out .how to update multiple list item records 
    Note(sharepoint hosted APP) only client side coding solution 
    function updateListItems() {
    var itemArray = [];
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('TestList');
    for(var i = 1; i<= 5; i++){
    var oListItem = oList.getItemById(i);
    oListItem.set_item('Title', 'My Updated Item!' + i);
    oListItem.update();
    itemArray[i] = oListItem;
    clientContext.load(itemArray[i]);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
    function onQuerySucceeded() {
    alert('Items Updated');
    function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    updateListItems();

    Have a look at the following link for your reference
    https://social.msdn.microsoft.com/Forums/office/en-US/fc91b7b5-6300-4302-af93-4fc697131ec5/client-object-model-update-multiple-list-items?forum=sharepointdevelopment
    You can modify CAML query to fetch rows that you want to fetch.
    Geetanjali Arora | My blogs |

  • Attach Item To List Item Using Powershell

    Hi Everyone
    Hoping someone can help me with a SharePoint Powershell Script i need to do..
    What I have is a Document Library with word documents and a list of items that these documents needs to be attached to.
    The document library and the list have a column in common, Customer Order No.
    I want to basically take all the items from the document library and attach them to the list items where the Customer Order No matches, is this possible with Powershell?
    Thanks in advance :) 

    [System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”)
    $filePath = "location"
    $siteUrl = "site"
    $spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
    $spWeb = $spSite.OpenWeb()
    $spList = $spWeb.lists["YourListName"]
    $spitem = $spList.Items.Add()
    $item = $splist.GetItemById($1)
    AddAttachment $item $filePath
    function AddAttachment($item, $filePath)
    $bytes = [System.IO.File]::ReadAllBytes($filePath)
    $item.Attachments.Add([System.IO.Path]::GetFileName($filePath), $bytes)
    $item.Update()
    $spitem.Update()
    w: http://www.the-north.com/sharepoint | t: @JMcAllisterCH | YouTube: http://www.youtube.com/user/JamieMcAllisterMVP

  • Write Survey List items on to Excell through C#

    Hi team,
    i am working on a requirement where in i need to export the survey list items on to a excell, there is a OOB option to export but i need to do ti programatically but the problem is teh Survey list does not have the items like other lists. i did try many
    things but i am not getting what i exactly need.
    i would want all the cloumns of teh surver and teh responses in an excell, when i use the gettable() it gives me lot of junk columns. i only need th questions ( fileds ) created by abd created date on to the excell.
    Thanks in Advance

    You can use SP object model, and from SpListItemCollection you can get data table object and from data table you can export data into excel as code shown below
    // Load Excel file.
    var workbook = ExcelFile.Load("Workbook.xls");
    // Select active worksheet from the file.
    var worksheet = workbook.Worksheets.ActiveWorksheet;
    // Extract the data from the worksheet to newly created DataTable starting at
    // first row and first column for 10 rows or until the first empty row appears.
    var dataTable = worksheet.CreateDataTable(new CreateDataTableOptions()
    StartRow = 0,
    StartColumn = 0,
    NumberOfRows = 10,
    ExtractDataOptions = ExtractDataOptions.StopAtFirstEmptyRow
    // Change the value of the first cell in the DataTable.
    dataTable.Rows[0][0] = "Hello world!";
    // Insert the data from DataTable to the worksheet starting at cell "A1".
    worksheet.InsertDataTable(dataTable,
    new InsertDataTableOptions("A1") { ColumnHeaders = true });
    // Save the file to XLS format.
    workbook.Save("DataTable.xls");
    http://www.gemboxsoftware.com/support/articles/import-export-datatable-xls-xlsx-ods-csv-html-net
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

  • CSOM - Fetching list item version history programmatically

    HI,
    Is it possible to get the List item version history programmatically using Client Object model?
    I have checked these links:
    http://www.learningsharepoint.com/2010/07/16/programmatically-get-document-version-history-using-client-object-model-sharepoint-2010/
    but was not able to achieve. I am not looking for Document library, but for a custom list.
    Thanks

    Hi,
    In SharePoint Object Model, there is a
    SPListItem.Versions property
    can help to “Gets the collection of item version objects that represent the versions of the item”.
    However, in SharePoint Client Object Model, this property is not available at this moment.
    A workaround is that we can create a custom WCF web service for consuming from client side, then in this web service, we can use Object Model to access the versions of a list
    item.
    About how to
    create and a custom WCF web service:
    http://nikpatel.net/2012/02/29/step-by-step-building-custom-wcf-services-hosted-in-sharepoint-part-i/
    This workaround would not be applied to SharePoint Online cause Object Model is needed.
    If there may be some better ideas or solutions about this topic, your sharing would be welcome.
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they
    help and unmark them if they provide no help. If you have feedback for TechNet
    Subscriber Support, contact [email protected]
    Patrick Liang
    TechNet Community Support

  • To display values in List Item through Dbms_SQL

    Hi,
    I want to write the dynamic sql in forms6.0 to built my query at runtime and display the result in List Item. I am getting an error ora-12703. If any person can help me in this problem it will be very happy for me.
    declare
    l_cursor integer;
    l_last_name varchar2(20);
    l_createstring1 varchar2(2000) ;
    l_first_name varchar2(20) ;
    l_id number(9);
    result integer;
    l_count number(2) := 0;
    x varchar2(200);
    y number(9);
    begin
    l_cursor := dbms_sql.open_cursor;
    l_createstring1 := 'select id, first_name, last_name from candi_pinfo ' ;
    dbms_sql.parse(l_cursor,l_createstring1, 2);
    dbms_sql.define_column(l_cursor,1,l_id);
    dbms_sql.define_column(l_cursor,2,l_last_name,20);
    dbms_sql.define_column(l_cursor,3,l_first_name,20);
    result := dbms_sql.execute(l_cursor);
    loop
    if dbms_sql.fetch_rows(l_cursor) = 0 then
    exit;
    end if;
    dbms_sql.column_value(l_cursor,1,l_id);
    dbms_sql.column_value(l_cursor,2,l_last_name);
    dbms_sql.column_value(l_cursor,3,l_first_name);
    l_count := l_count+1;
    add_list_element('candi_id',l_count,l_id&#0124; &#0124;l_last_name&#0124; &#0124;l_first_name,l_id);
    end loop;
    dbms_sql.close_cursor(l_cursor);
    :result.candi_id := get_list_element_value('candi_id',1);
    exception
    when others then
    dbms_sql.close_cursor(l_cursor);
    raise;
    end;
    null

    Hi reddy,
    I didn't find any error in your code and I tested in my system by changing query.. and it is working fine.. check declaration of variables datatype ,length etc..
    I tested following code ..
    declare
    l_cursor integer;
    l_last_name varchar2(40);
    l_createstring1 varchar2(2000) ;
    l_first_name varchar2(200) ;
    l_id number(9);
    result integer;
    l_count number(5) := 0;
    x varchar2(200);
    y number(9);
    begin
    --clear_list('lb');
    l_cursor := dbms_sql.open_cursor;
    l_createstring1 := 'select col1,col2 from mytable ' ;
    dbms_sql.parse(l_cursor,l_createstring1, 2);
    dbms_sql.define_column(l_cursor,1,l_id);
    dbms_sql.define_column(l_cursor,2,l_last_name,40);
    result := dbms_sql.execute(l_cursor);
    loop
    if dbms_sql.fetch_rows(l_cursor) > 0 then
    dbms_sql.column_value(l_cursor,1,l_id);
    dbms_sql.column_value(l_cursor,2,l_last_name);
    --dbms_sql.column_value(l_cursor,3,l_first_name);
    l_count := l_count+1;
    add_list_element('candi_id',l_count,to_char(l_id)&#0124; &#0124;l_last_name,l_id);
    else
    exit;
    end if;
    end loop;
    dbms_sql.close_cursor(l_cursor);
    :result.candi_id := get_list_element_value('candi_id',1);
    exception
    when others then
    dbms_sql.close_cursor(l_cursor);
    end;

  • List items archival with version history using powershell

    HI
    Is there any way to work with site and content structure in SharePoint 2010 with power-shell.
    I want to run a automated task(power shell script) to move list items from source to destination in the same site with version history.
    I know i can do it from site and content organizer but i have to do manually and SharePoint designer workflows doesn't retain the version history.
    Please give me  your valuable tips.

    Hi Manikanta,
    Archive ListItem with Version History in SharePoint, I suggesting you the best links for your solution here
    http://techno-sharepoint.blogspot.sg/2012/10/moving-sharepoint-list-items-to-archive.html
    http://get-spscripts.com/2011/10/copy-sharepoint-lists-and-document.html
    For more details, reach us at
    <a href="http://staygreenacademy.com/sharepoint-2013-training/">SharePoint 2013 Online Training</a>

Maybe you are looking for

  • System not re-installing Microphoto player, stuck in install/fail lo

    I recently upgraded my hard dri'ves and, after some reinstalling and troubleshooting, most everything is back up and running... except my Zen Microphoto. Whenever I plug it into a USB port, XP detects it as an "MTP Device" and tries to install the dr

  • A question about role

    Hello Expert, I'm a beginner in BW. Now I'm trying to generate Demo Content for InfoCube SAP DemoCube(0D_DECU) and use it in query. But I'm blocked by installing role SAP_BWC_0D_SAPDEMO   (I got the role from the data flow network of the InfoCube). I

  • Override Existing functionality in OO ALV

    Hi Can any one give me the procedure to override the standard functionality associcate with the buttons in ALV Toolbar. I am not able debug the when the user perfroms action on the Standard ALV toolbar. Can you help me Thanks all.

  • Capital Drive Name For Boot Camp Disk

    I have XP installed via Boot Camp, as a separate partition, so it appears on my desktop, however the name of the Windows drive is always in capital letters. Does anyone know how to change this so that "indows" is in capital letters? This is a purely

  • Adobe Reader XI installed but "Not Found"

    I have Adobe Reader XI installed and apparently running normally. Unfortunately the UK's Parcelforce web-site says it can't find it. I get the message " Adobe Acrobat NOT found. You must have Adobe Reader (5 or better) with the browser plugin properl