I am trying to update the web.config file through Powershell using the SharePoint class "SPWebConfigModification" however facing the issue mentioned below, please help me to fix this.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$url = New-Object System.Uri("http://serverName:port/")
$webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)
$mod = New-Object -TypeName "Microsoft.SharePoint.Administration.SPWebConfigModification"
$mod.Path = "configuration/system.web/customErrors"
$mod.Name = "mode"
$mod.Sequence = 0
$mod.Owner = "powershell"
$mod.Type = "EnsureAttribute"
$mod.Value = "Off"
$webApp.WebConfigModifications.Add($mod)
$webApp.WebService.ApplyWebConfigModifications()
$webApp.Update()
Error:
Exception calling "ApplyWebConfigModifications" with "0" argument(s): "'' is an invalid expression."
At line:1 char:47
+ $webApp.WebService.ApplyWebConfigModifications <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException