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:
"<nativehr>0x80070003</nativehr><nativestack></nativestack>".
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.Url
$site.RootWeb.SiteAdministrators
$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
$Site.Dispose()
Help please before I go mental :(