# Cant open path from xml file? what am i doing wrong?

**URL:** <https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517>\
**Category:** PowerShell Help\
**Created:** [October 13, 2017, 1:56pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517 "2017-10-13T13:56:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![longquo](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@longquo](https://forums.powershell.org/u/longquo)\
**Post date:** [October 13, 2017, 1:56pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/1 "2017-10-13T13:56:55Z")

</div>

xml file: [AppDeployToolkitConfig.xml - Pastebin.com](https://pastebin.com/5QJFnFyW)

```
$xmlfile = "c:\tmp\AppDeployToolkitConfig.xml"
$oXMLDocument = New-Object System.XML.XMLDocument
$oXMLDocument.Load($xmlfile)

$openlogDir = $($oXMLDocument.AppDeployToolkit_Config.Toolkit_Options.Toolkit_LogPath)

[string]$envWinDir = $env:WINDIR

Write-host $openlogDir

explorer $openlogDir
```

get this error  
Invoke-Item : Cannot find path ‘C:$envWinDir\Logs\Software’ because it does not exist.

but the write-host seem fine??  
$envWinDir\Logs\Software

This works fine invoke-item C:\Windows\Logs\Software

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [October 13, 2017, 2:23pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/2 "2017-10-13T14:23:31Z")

</div>

Well, firstly, this…

$envWinDir\Logs\Software

… is wrong.

There is no such variable in the system.  
It should be …

$env:WinDir\Logs\Software

…notice the required colon.

List all environment variables this way  
Get-Childitem -Path env:\

Pick environment variables this way…  
$env:[Choose one from the environment listing above]

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 13, 2017, 2:32pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/3 "2017-10-13T14:32:26Z")

</div>

I agree with postanote that the syntax of the path in the XML file is incorrect.  
Your handling of the XML file also seems a bit convoluted. I would do something like this:

```
[xml]$xml = Get-Content E:\__Temp\appdeploytoolkitconfig.xml
$openlogDir = $xml.AppDeployToolkit_Config.Toolkit_Options.Toolkit_LogPath
```

---

<div class="post-metadata">

**Author:** ![longquo](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@longquo](https://forums.powershell.org/u/longquo)\
**Post date:** [October 13, 2017, 3:15pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/4 "2017-10-13T15:15:59Z")

</div>

the xml it not mine but from the toolkit  
to fix the env i do this  
[string]$envWinDir = $env:WINDIR

but it does not work…

---

<div class="post-metadata">

**Author:** ![longquo](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@longquo](https://forums.powershell.org/u/longquo)\
**Post date:** [October 13, 2017, 3:22pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/5 "2017-10-13T15:22:02Z")

</div>

your sample open quick access

should do a replace string??

$envWinDir\Logs\Software

to

$env:WinDir\Logs\Software

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [October 13, 2017, 6:27pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/6 "2017-10-13T18:27:55Z")

</div>

Yes, as stated, that $envWinDir is not a correct environment variable.

However, # # Well… Let’s just walk through this shall we…

PS D:\Scripts\> ‘Define the path to the XML file’

($xmlfile = “D:\Scripts\AppDeployToolkitConfig.xml”)  
Test-Path -Path $xmlfile  
Define the path to the XML file  
D:\Scripts\AppDeployToolkitConfig.xml  
True

PS D:\Scripts\> 'Creating a new object ’

($oXMLDocument = New-Object System.XML.XMLDocument)  
Creating a new object

NodeType : Document  
ParentNode :  
DocumentType :  
Implementation : System.Xml.XmlImplementation  
Name : #document  
LocalName : #document  
…

PS D:\Scripts\> ‘load the xml file’

($oXMLDocument.Load($xmlfile))  
load the xml file  
Exception calling “Load” with “1” argument(s): “There is no Unicode byte order mark. Cannot switch to Unicode.”  
At line:2 char:1

- ($oXMLDocument.Load($xmlfile))
- 

```auto
  + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : DotNetMethodException

```

PS D:\Scripts\> ‘open the logdir per the xml document options path’

($openlogDir = $($oXMLDocument.AppDeployToolkit\_Config.Toolkit\_Options.Toolkit\_LogPath))  
Test-Path -Path $openlogDir  
open the logdir per the xml document options path  
Test-Path : Cannot bind argument to parameter ‘Path’ because it is null.  
At line:3 char:17

- Test-Path -Path $openlogDir
- 

```
            ~~~~~~~~~~~

```

  - CategoryInfo : InvalidData: (🙂 [Test-Path], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

PS D:\Scripts\> ‘Get the Windows directory’

([string]$envWinDir)  
Test-Path -Path $envWinDir  
Get the Windows directory

Test-Path : Cannot bind argument to parameter ‘Path’ because it is null.  
At line:3 char:17

- Test-Path -Path $envWinDir
- 

```
            ~~~~~~~~~~

```

  - CategoryInfo : InvalidData: (🙂 [Test-Path], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

PS D:\Scripts\> ‘Open the logdir based on options settings’

Test-Path -Path $openlogDir  
Open the logdir based on options settings  
Test-Path : Cannot bind argument to parameter ‘Path’ because it is null.  
At line:2 char:17

- Test-Path -Path $openlogDir
- 

```
            ~~~~~~~~~~~

```

  - CategoryInfo : InvalidData: (🙂 [Test-Path], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand

########################

# So, based on the above, ther are problems well before you start hitting the path stuff.

The reality of your file’s encoding appears to conflict with that specified by  
your XML declaration. If your file actually uses one-byte characters, declaring  
encoding=“utf-16” won’t change it to use two-byte characters, for example.

Try removing the conflicting encoding from the XML declaration. Replace

with

You may also be able to load the file into a string as a work-around using LoadXML().

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [October 13, 2017, 6:35pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/7 "2017-10-13T18:35:01Z")

</div>

I meant to add this but hit send to soon.

Point of note :  
I do not have the AppDeployToolKit in my environment as it is not needed for what I do at this time

# After commenting out the version entry in the XML file

##########  
xml version=“1.0” encoding=“utf-16”  
##########

‘Define the path to the XML file’  
($xmlfile = “D:\Scripts\AppDeployToolkitConfig.xml”)  
Test-Path -Path $xmlfile

'Creating a new object ’  
($oXMLDocument = New-Object System.XML.XMLDocument)

‘load the xml file’  
($oXMLDocument.Load($xmlfile))

‘open the logdir per the xml document options path’  
($openlogDir = $($oXMLDocument.AppDeployToolkit\_Config.Toolkit\_Options.Toolkit\_LogPath))  
Test-Path -Path $openlogDir

‘Get the Windows directory’  
([string]$envWinDir = $env:windir)  
Test-Path -Path $envWinDir

‘Open the logdir based on options settings’  
Test-Path -Path $openlogDir

‘open the logdir’  
explorer $openlogDir

# get this error

# Invoke-Item : Cannot find path ‘C:$envWinDir\Logs\Software’ because it does not exist.

# but the write-host seem fine??

“$envWinDir\Logs\Software”

# This works fine

invoke-item ‘C:\Windows\Logs\Software’

# Resutls

PS D:\Scripts\> ‘Define the path to the XML file’  
($xmlfile = “D:\Scripts\AppDeployToolkitConfig.xml”)  
Test-Path -Path $xmlfile  
Define the path to the XML file  
D:\Scripts\AppDeployToolkitConfig.xml  
True

PS D:\Scripts\> 'Creating a new object ’  
($oXMLDocument = New-Object System.XML.XMLDocument)  
Creating a new object

NodeType : Document  
ParentNode :  
DocumentType :  
Implementation : System.Xml.XmlImplementation  
Name : #document  
LocalName : #document  
DocumentElement :  
OwnerDocument :  
Schemas : System.Xml.Schema.XmlSchemaSet  
XmlResolver :  
NameTable : System.Xml.NameTable  
PreserveWhitespace : False  
IsReadOnly : False  
InnerText :  
InnerXml :  
SchemaInfo : System.Xml.Schema.XmlSchemaInfo  
BaseURI :  
Value :  
ChildNodes : {}  
PreviousSibling :  
NextSibling :  
Attributes :  
FirstChild :  
LastChild :  
HasChildNodes : False  
NamespaceURI :  
Prefix :  
OuterXml :  
PreviousText :

PS D:\Scripts\> ‘load the xml file’  
($oXMLDocument.Load($xmlfile))  
load the xml file

PS D:\Scripts\> ‘open the logdir per the xml document options path’  
($openlogDir = $($oXMLDocument.AppDeployToolkit\_Config.Toolkit\_Options.Toolkit\_LogPath))  
Test-Path -Path $openlogDir  
open the logdir per the xml document options path  
$envWinDir\Logs\Software  
False

PS D:\Scripts\> ([string]$envWinDir = $env:windir)  
Test-Path -Path $envWinDir  
C:\WINDOWS  
True

PS D:\Scripts\> ‘Open the logdir based on options settings’  
Test-Path -Path $openlogDir  
Open the logdir based on options settings  
False

---

<div class="post-metadata">

**Author:** ![longquo](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@longquo](https://forums.powershell.org/u/longquo)\
**Post date:** [October 14, 2017, 5:56am UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/8 "2017-10-14T05:56:38Z")

</div>

```
[xml]$xml = Get-Content "$scriptPath\AppDeployToolkit\AppDeployToolkitConfig.xml"
	$openlogDir = $xml.AppDeployToolkit_Config.Toolkit_Options.Toolkit_LogPath
	$logPath = $openlogDir -replace '\$envWinDir', $env:WinDir
	return $logPath
```

I did a replace to get around the wrong env

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/cant-open-path-from-xml-file-what-am-i-doing-wrong/9517/9 "2024-05-16T20:37:24Z")

</div>


