0

Hello everyone i dont know if this question is asked before but i need to update couple of values in a xml file using powershell i have the following code it works local but on tfs it doesn't work i get the following error System.Management.Automation.MethodInvocationException: Exception calling "ReadAllText" with "1" argument(s): "Value cannot be null.

And i have the following code

$EmployeeData= "C:\files\Employees.xml"
$oldEmployeeID= "23"
$NewEmployeeID= "25"

$content = [System.IO.File]::ReadAllText($EmployeeData).Replace($oldEmployeeID, $NewEmployeeID)
[System.IO.File]::WriteAllText($EmployeeData, $content)

localy it works but on tfs its crashes does anybody know why with the following error code

System.Management.Automation.MethodInvocationException: Exception calling "ReadAllText" with "1" argument(s): "Value cannot be null.
1
  • Could you elaborate "on tfs it doesn't work"? Did you include the script in TFS build? How's your build definition like? Which version of TFS are you using? Commented Apr 19, 2018 at 8:35

2 Answers 2

1

You do not need to use this. You can directly parse XML in powershell by type casting:

$EmployeeData= "C:\files\Employees.xml"
$oldEmployeeID= "23"
$NewEmployeeID= "25"

[XML]$content = Get-Content $EmployeeData

Then you can access $content.elementId or $content.nodename.

Follow THIS for your reference.

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to update values/tokens in a XML file during TFS build, a simple way is to use Replace Tokens task or Tokenization Task in your build definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.