jeudi 12 mars 2015

SharePoint Online: Change properties



I am retrieving a change log for SharePoint Online site, but I am particularly interested in the who performed the change and on what item.



$changeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery $true,$true
$changeCollection = $ctx.Site.GetChanges($changeQuery)
$ctx.Load($changeCollection)
$ctx.ExecuteQuery()


I found this post, but when I export my changes to a csv, in Excel I don't see ItemId or UserId. I see those properties in the Powershell window as the script runs.


The Excel file looks like it looks, because not all elements include those properties. The columns in Excel come from the properties of the first retrieved item. Fine. I tried to use a rather clumsy workaround, by half-manually adding those properties to elements if they are not there:



foreach ($change in $changeCollection)
{
$change | Add-Member ItemName("Not Applicable")
$change | Add-Member ListName("Not Applicable")


if(-Not $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("Not Applicable")} else { $change["ItemName"]=$ctx.Web.Lists.GetById($change.ListId).GetItemById($change.ItemId).LeafName}
if(! $change.IsPropertyAvailable("ListId")) { $change | Add-Member ListId("Not Applicable")}


Write-Output $change
}


but I am receiving an error:



Unable to index into an object of type Microsoft.SharePoint.Client.ChangeItem. At C:\Users\ivo\Desktop\wiki\technet\changecollection.ps1:53 char:104 + if(-Not $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("No ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : CannotIndex



Questions: (answer to any of them will solve my trouble)

How to check if the property is available?

How to export to csv a jagged array/items with varied properties?


Of course any other more enlightened solution is most welcome.








0 commentaires:

Enregistrer un commentaire