I got following error when I tried to remove item from the WebConfigModification.
Exception calling "Remove" with "1" argument(s): "Object reference not set to a n instance of an object."
I need to remove all the entries from webConfigModification where owner is PowerShell.
$webApp = Get-SPWebApplication "myhomesite.com"
$webApp.WebConfigModifications
**This returns:**
Name : add[@key="RedirectToHelloPage"]
Path : configuration/appSettings
Sequence : 0
Owner : PowerShell
Value : <add key="RedirectToHelloPage" value="Hello.aspx" />
Type : EnsureChildNode
UpgradedPersistedProperties : {}
Name : add[@key="IsString"]
Path : configuration/appSettings
Sequence : 0
Owner : PowerShell
Value : <add key="IsString" value="false" />
Type : EnsureChildNode
UpgradedPersistedProperties : {}
Name : add[@key="IsString"]
Path : configuration/appSettings
Sequence : 0
Owner : PowerShell112
Value : <add key="IsString" value="false" >
Type : EnsureChildNode
UpgradedPersistedProperties : {}
And I want to Remove all entries with Owner = PowerShell
$config = $webApp.WebConfigModifications | Where-Object {$_.Owner -eq "PowerShell"}
$webApp.WebConfigModifications.Remove($config)
$webApp.Update()
$webApp.Parent.ApplyWebConfigModifications()
$config contains:
PS C:\> write-host $config
Microsoft.SharePoint.Administration.SPWebConfigModification
But I always get above mentioned error: Can somebody help?