Getting an error but still changing value of key in app.config with powershell -


i'm trying simple script change configuration key in app.config using powershell script this

dir *.config -recurse -pipelinevariable webconfig |     foreach {         $doc = [xml] (get-content $_)         $environment = $doc.configuration.appsettings.add | {$_.key -eq 'environment'}          ($environment).value = "ci"         $doc.save($webconfig)          }  

the problem when run i'm getting

the property 'value' cannot found on object. verify property exists , can set. 

at line:5 char:9

but if after running script , getting error run same script without assignment, i.e.

dir *.config -recurse -pipelinevariable webconfig |     foreach {         $doc = [xml] (get-content $_)         $environment = $doc.configuration.appsettings.add | {$_.key -eq 'environment'}          ($environment).value         $doc.save($webconfig)          }  

it displays value changed (which confirmed in actual file).

so i'm lost here,

thanks

it seems me fail when checking config files don't include environment app setting. try checking see if $environment not null before setting value.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -