Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

A custom solution was installed at one point, and was removed do to it not functioning as expected. after the solution was removed several fields remained, and I'm trying to remove them with the script below.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
$w = Get-SPWeb http://spdev1
$f = $w.Fields
$f.Delete("slamidnumber")
$f.Update()

When running the script, i'm getting the following error:

PS C:\Users\user\Desktop> $f.Delete("slamidnumber")
Exception calling "Delete" with "1" argument(s): "Value does not fall within
the expected range."
At line:1 char:1
+ $f.Delete("slamidnumber")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException

I have also tried the following with similar results:

PS C:\Users\jwhite\Desktop> $f.Fields("slamidnumber").Delete()
Method invocation failed because [Microsoft.SharePoint.SPFieldBoolean] doesn't
contain a method named 'Fields'.
At line:1 char:1
+ $f.Fields("slamidnumber").Delete()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

after running the recommended changes, I'm getting the following error:

PS C:\Users\user\Desktop> $f.Fields["slamidnumber"].Delete()
An error occurred while enumerating through a collection: Field type
SlamIdField is not installed properly. Go to the list settings page to delete
this field. .
At line:1 char:1
+ $f.Fields["slamidnumber"].Delete()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Microsoft.Share...on+SPEnumer
ator:SPEnumerator) [], RuntimeException
+ FullyQualifiedErrorId : BadEnumeration
share|improve this question

2 Answers 2

Try this one...

$w = Get-SPWeb http://spdev1
$f = $w.Fields["slamidnumber"]
$f.Sealed = $false
$f.Update()
$f.Delete()
share|improve this answer
    
unfortunately the sealed property is not available for object –  Jason Sep 3 '13 at 14:21

Use square brackets on the `Fields' property, which hangs off the web variable.

$w.Fields["slamidnumber"].Delete()

share|improve this answer
    
you suggestion did resolve my initial error, now i'm running into a new issue (added to my initial post) –  Jason Sep 2 '13 at 19:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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