Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. $listTitle = "Workflow History"
  2. $csvFilePath = "C:Tempitems.csv"
  3. $sSiteColUrl = ""
  4. $sUserName = ""
  5. $sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
  6. $accountName = ""
  7.  
  8. try
  9. {
  10. #Adding the Client OM Assemblies
  11. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  12. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  13.  
  14. #SPO Client Object Model Context
  15. $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
  16. $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
  17. $spoCtx.Credentials = $spoCredentials
  18.  
  19. [Microsoft.SharePoint.Client.List]$list = $spoCtx.Web.Lists.GetByTitle($listTitle)
  20.  
  21. #Use CamlQuery if you want to filter
  22. #$query = New-Object Microsoft.SharePoint.Client.CamlQuery
  23. #$query.ViewXml = ""
  24. #[Microsoft.SharePoint.Client.ListItemCollection]$items = $list.GetItems($query)
  25.  
  26. #Get all items
  27. $listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
  28. $spoCtx.Load($listItems)
  29. $spoCtx.ExecuteQuery()
  30.  
  31. $itemCollection = @()
  32.  
  33. $listItems | foreach {
  34. $exportItem = New-Object PSObject
  35. $exportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["WorkflowInstance"]
  36. $exportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["WorkflowAssociation"]
  37. $exportItem | Add-Member -MemberType NoteProperty -Name "User" -value $_["User"].LookupValue
  38. $exportItem | Add-Member -MemberType NoteProperty -Name "Desc" -value $_["Description"]
  39. $itemCollection += $exportItem
  40. }
  41. $itemCollection | Export-Csv -Path $csvFilePath
  42.  
  43. $spoCtx.Dispose()
  44. }
  45. catch [System.Exception]
  46. {
  47. write-host -f red $_.Exception.ToString()
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement