Change directory in powershell script using an XML conf File

Viewed 82

Im trying to change my working directory in a powershell script using a XML config file. I have an XML file named "conf.xml" which look like this :


<?xml version="1.0" encoding="UTF-8"?>
<Config>
    <Paths>
        <pathAW>D:\Workspace</pathAW>
    </Paths>
</Config>

And I have an powershell script named "test.ps1" which look like this :


[xml]$ConfigFile = Get-Content "conf.xml"
cd $ConfigFile.Config.Paths.pathAW

When I want to run this script with a simple command :

PS D:\>test.ps1 

from the powershell command prompt Im getting this error :

The argument could not be processed because the value of the "path" argument is Null. Replace the value of the "path" argument with a non-null value.

Yet it works when I run the script lines one by one in the powershell command prompt like this :

PS D:\>[xml]$ConfigFile = Get-Content "conf.xml"
PS D:\>cd $ConfigFile.Config.Paths.pathAW
PS D:\Workspace>
0 Answers
Related