We are running a PowerShell script on our farm at the moment to pull all the users and their permissions. The script is working fine on all of our sites, but one is giving us the following error:

The following exception occurred while trying to enumerate the collection: 
At line:5 char:5
+     $site.RootWeb.SiteGroups | Select Name, Owner, Users
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

This seems to be throwing off our ability to output the data to a CSV file. So my question if you lovely people could answer is What would cause this? And how would we find out what it is related to?

Below is the script we are using to pull the data:

Get-SPWebApplication http://localhost | Get-SPSite -Limit All | where {($_.RootWeb.WebTemplateId -ne 54) -and ($_.RootWeb.WebTemplateId -ne 21)} | % {
  $site = $_
  $site.RootWeb.SiteGroups | Select Name, Owner, Users
  #$site.RootWeb.RoleDefinitions | Select Name, BasePermissions

$groups = $site.RootWeb.SiteGroups

function Get-SPGroup() {
  foreach ($grp in $groups) {
    foreach ($user in $grp.users) {
      $hash = @{"URL" = $site.Rootweb.url; "Group" = $grp.name; "User" = $user.name}
      New-Object PSObject -Property $hash | Sort-Object

Get-SPGroup | Export-csv C:\Users\*****\Desktop\permissions-list.csv


Help please before I go mental :(

  • Can you check if you have appropriate permissions on this site? – Zdeněk Vinduška Jan 9 '19 at 12:29
  • I do, I am running this with the farm account with this, I am also able to run the script on other site collections as the farm account and on my own account. – Chris. D Jan 9 '19 at 13:31
  • Can you access that site, maybe it is orphaned. – Marek Sarad Jan 9 '19 at 13:38
  • The script works fine for me. Yes, check the site or the groups which you want to export, if there is any orphan or not. – Zdeněk Vinduška Jan 9 '19 at 13:42
  • We can access all the sites that are throwing this message up, we will run a check if there is a correlation between orphaned sites and the error. I will update in min. PERFECT!!! They are Orphaned , that might be it, we are going to fix the sites and come back to you, thank you for the suggestions :) – Chris. D Jan 9 '19 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.