Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. *ToolId* *ProductId*
  2.  
  3. T001 ProductA
  4. T001 ProductB
  5. T002 ProductA
  6. T002 ProductC
  7.  
  8. *ToolId* *ProductId*
  9.  
  10. T001 ProductA; ProductB
  11. T002 ProductA; ProductC
  12.  
  13. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  14.  
  15. #Get the context
  16. $ctx = Get-SPServiceContext https://path
  17.  
  18. #Get the scope
  19. $scope = new-object Microsoft.SharePoint.SPServiceContextScope $ctx
  20.  
  21. #Get the target site collection
  22. $webTarget = Get-SPWeb -identity "https://path"
  23.  
  24. #Get the Target List
  25. $list = $webTarget.Lists["Name of List"]
  26.  
  27. #Array to Hold Result - PSObjects
  28. $ListItemCollection = @()
  29.  
  30. #Get All List items
  31. $list.Items | Where-Object { $_["ToolId"] -ne ''} | foreach {
  32. $ExportItem = New-Object PSObject
  33. $ExportItem | Add-Member -MemberType NoteProperty -name "ToolId" -value $_["ToolId"]
  34. $ExportItem | Add-Member -MemberType NoteProperty -name "ProductId" -value $_["ProductId"]
  35. #Add the object with property to an Array
  36. $ListItemCollection += $ExportItem
  37. }
  38. #Export the result Array to CSV file
  39. $ListItemCollection | Export-CSV "\pathtest.csv" -NoTypeInformation
  40. #Dispose the web Object
  41. $webTarget.Dispose()
  42.  
  43. $ListItemCollection | Group-Object ToolId |
  44. Select @{ Label = "ToolId"; Expression = { $_.Name } }, @{ Label = "Products"; Expression = { ($_.Group | Select-Object -ExpandProperty ProductId) } }
  45.  
  46. $ListItemCollection | group ToolId | select @{ L = "ToolId"; E = { $_.Name } }, @{ L = "Products"; E = { $_.Group.ProductId } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement