0

I'm a newby to both powershell scripting and Sharepoint. I am trying to write the following powershell script that will get all site columns from my Sharepoint 2010 site and put them in a csv file.

Add-PsSnapin Microsoft.SharePoint.PowerShell
$url = <My Site URL>
$fileName = "<MyDirectory>\siteColumns.csv"
"Column Title `t Site Column ID `t InternalName `t StaticName `t MaxLength `t Description `t Group `t TypeShortDescription " | out-file $fileName

$site = new-object Microsoft.SharePoint.SPSite($url)
$web = $site.rootweb.Fields
echo "Generation File..."
ForEach ($id in $web)
{
    "$($id.Title) `t $($id.Id) `t $($id.InternalName) `t $($id.StaticName) `t $($id.MaxLength)/$($id.MaxLength) `t $($id.Description) `t $($id.Group) `t $($id.TypeShortDescription) " | Out-File $fileName -Append
}
$site.Dispose()

The script runs fine until it reaches the ForEach loop. When it reaches this point I am getting the following error:

The following exception was thrown when trying to enumerate the collection: "Attempted to perfo
rm an unauthorized operation.".
At C:\Users\IP2560_a\Documents\PSScripts\GetSiteColumns.ps1:9 char:8
+ ForEach <<<<  ($id in $web)
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator

I am running in a shell that has Administrator error. Are there any permissions I need to set up in Sharepoint itself or something else?

Any help would be appreciated.

1 Answer 1

2

SharePoint farm admin account not granted rights for site collections automatically, try to add the account to your site collection owners group(I tested your script, working fine).

Update: enter image description here

5
  • Thank you @Lee_MSFT I am told I am already an administrator. Where do i go to check this? Is it in Security > Users > Manage the farm adminstrators group? Or Application Management > Change Site Collection Administrators? Should I be on both those lists?
    – Ian Parry
    Nov 13, 2018 at 2:03
  • Go to site collection and try to add the user to Site Settings->Site permissions : site Owners group.
    – Lee
    Nov 13, 2018 at 2:47
  • Hmm. I seem to get access denied when I try to hit the url now. It looks like there is something else going on here. Thanks for your help.
    – Ian Parry
    Nov 13, 2018 at 3:09
  • You could add the user as administrator by user policy in farm admin center if you can't access site collection, check the update screenshot.
    – Lee
    Nov 13, 2018 at 3:32
  • Finally got this solved. Even though I was set up as a site administrator I wasn't able to gain access. When I was removed and then re added as an administrator it worked. Thanks for your assistance Lee.
    – Ian Parry
    Nov 14, 2018 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.