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.