Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $listTitle = "Workflow History"
- $csvFilePath = "C:Tempitems.csv"
- $sSiteColUrl = ""
- $sUserName = ""
- $sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
- $accountName = ""
- try
- {
- #Adding the Client OM Assemblies
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- #SPO Client Object Model Context
- $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
- $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
- $spoCtx.Credentials = $spoCredentials
- [Microsoft.SharePoint.Client.List]$list = $spoCtx.Web.Lists.GetByTitle($listTitle)
- #Use CamlQuery if you want to filter
- #$query = New-Object Microsoft.SharePoint.Client.CamlQuery
- #$query.ViewXml = ""
- #[Microsoft.SharePoint.Client.ListItemCollection]$items = $list.GetItems($query)
- #Get all items
- $listItems = $list.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
- $spoCtx.Load($listItems)
- $spoCtx.ExecuteQuery()
- $itemCollection = @()
- $listItems | foreach {
- $exportItem = New-Object PSObject
- $exportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["WorkflowInstance"]
- $exportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["WorkflowAssociation"]
- $exportItem | Add-Member -MemberType NoteProperty -Name "User" -value $_["User"].LookupValue
- $exportItem | Add-Member -MemberType NoteProperty -Name "Desc" -value $_["Description"]
- $itemCollection += $exportItem
- }
- $itemCollection | Export-Csv -Path $csvFilePath
- $spoCtx.Dispose()
- }
- catch [System.Exception]
- {
- write-host -f red $_.Exception.ToString()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement