How to modify null value/two double quotes that contain nothing in xml with Powershell?

I need to modify web.config file which I am reading as xml and the line i need to change is this:

<add key="My.Unique.Repository" value="" /> 

as you can see, there is nothing in value=" " just the double quotes.

I have no script written for this, I am trying to find out how to do it in the simplest way before I attempt to compile code

P.S. I have zero powershell experience, kindly respond in simple terms, thank you

Add Comment
2 Answer(s)

Probably something along the lines of

    $xml = [xml]'<add key="My.Unique.Repository" value="" />'      $target = $xml.SelectSingleNode("/add")     $target.SetAttribute("value", "some value"); 
Add Comment

Found the answer that I needed, see the code below. Thanks Theo for providing me with this answer. https://stackoverflow.com/users/9898643/theo

$path        = '\\lonngp-ap\c$\Program Files\AIR\IIS\web2.config' [xml]$config = Get-Content -Path $path -Raw $stuffIwant  = "\\StringServer123" $config.SelectNodes("//add[@key='My.Unique.Repository']") | ForEach-Object { $_.SetAttribute("value", $stuffIwant) } $config.Save($path)  
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.