Hello,I am trying to update a connection string in an XML file using POWERSHELL. I have the following code that is not working. I have a code snippet for the XML file and my PS script below.Any help would be appreciated! BigGrinPOWERSHELL script# Read configuration file in a XML variable$webConfig = 'C:\MyXML.dtsConfig'$doc = (Get-Content $webConfig) -as [Xml]$root = $doc.get_DocumentElement();$newCon = $root.Configuration.add.ConfiguredValue.Replace('Data Source=NYD','Data Source=MILANOMOSH');$root.Configuation.add.ConfiguredValue = $newCon$doc.Save($webConfig)XML File OUTPUT<?xml version="1.0"?><DTSConfiguration><DTSConfigurationHeading><DTSConfigurationFileInfo GeneratedBy="NA\John.Doe" GeneratedFromPackageName="MP_FEED_MAIN" GeneratedFromPackageID="{E80FF572-65D9-49D3-9B19-B5975A29F663}" GeneratedDate="4/11/2016 2:10:27 PM" /></DTSConfigurationHeading><Configuration ConfiguredType="Property" Path="\Package.Connections[NYD.DATABASE].Properties[ConnectionString]" ValueType="String"><ConfiguredValue>Data Source=NYD;Initial Catalog=DBNAME;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;</ConfiguredValue></Configuration></DTSConfiguration>ERROR MESSAGEYou cannot call a method on a null-valued expression.At line:6 char:58+ $newCon = $root.Configuration.add.ConfiguredValue.Replace <<<< ('Data Source=NYD','Data Source=MANDOMOSH');+ CategoryInfo : InvalidOperation: (Replace:String) [], RuntimeException+ FullyQualifiedErrorId : InvokeMethodOnNullProperty 'Replace' cannot be found on this object; make sure it exists and is settable.At line:7 char:41+ $root.Configuration.add.ConfiguredValue. <<<< Replace = $newCon+ CategoryInfo : InvalidOperation: (Replace:String) [], RuntimeException+ FullyQualifiedErrorId : PropertyNotFound
↧