Answered by:
Remove Web Property using powershell

Question
-
Hi,
I am trying to remove web property using below powershell command however it is failing to do so. Any help is appreciated on this:
Set-ExecutionPolicy RemoteSigned [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $fullUrl = 'http://mysite.com/ABC/X' $site = New-Object -Type Microsoft.SharePoint.SPSite -ArgumentList $fullUrl $web = $site.OpenWeb() $key="My_Key"; $web.AllProperties.Remove[$key] $web.Properties[$key] = $null; $web.Properties.Update() $web.Update() $web.Dispose() $site.Dispose()
I get below error message:
Unable to index into an object of type System.Management.Automation.PSMethod.
Wednesday, October 11, 2017 6:52 AM
Answers
-
Hi,
You can use the below statement to remove the property value based on the Key. You are trying to index into the property bag. Instead of index [] , access the property using () :
$web.AllProperties.Remove('My_Key')
You may try out the code as :
Set-ExecutionPolicy RemoteSigned [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $fullUrl = 'http://mysite.com/ABC/X' $site = New-Object -Type Microsoft.SharePoint.SPSite -ArgumentList $fullUrl $web = $site.OpenWeb() $key="My_Key"; $web.AllProperties.Remove('My_Key') // this is a key $web.Update() $web.Dispose() $site.Dispose()
Please Up Vote and Mark this as Answer if it helps.
- Marked as answer by Kodnil Wednesday, October 11, 2017 9:36 AM
Wednesday, October 11, 2017 8:27 AM
All replies
-
$web.DeleteProperty($key)
顺其自然地勇往直前!—Justin Liu
Wednesday, October 11, 2017 8:08 AM -
This does not work. I am getting error:
Method invocation failed because [Microsoft.SharePoint.SPWeb] doesn't contain a method named 'DeleteProperty'.
Wednesday, October 11, 2017 8:16 AM -
what is your sharepoint version?
顺其自然地勇往直前!—Justin Liu
Wednesday, October 11, 2017 8:20 AM -
Hi,
You can use the below statement to remove the property value based on the Key. You are trying to index into the property bag. Instead of index [] , access the property using () :
$web.AllProperties.Remove('My_Key')
You may try out the code as :
Set-ExecutionPolicy RemoteSigned [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $fullUrl = 'http://mysite.com/ABC/X' $site = New-Object -Type Microsoft.SharePoint.SPSite -ArgumentList $fullUrl $web = $site.OpenWeb() $key="My_Key"; $web.AllProperties.Remove('My_Key') // this is a key $web.Update() $web.Dispose() $site.Dispose()
Please Up Vote and Mark this as Answer if it helps.
- Marked as answer by Kodnil Wednesday, October 11, 2017 9:36 AM
Wednesday, October 11, 2017 8:27 AM