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

xml file: AppDeployToolkitConfig.xml - Pastebin.com

$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

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]

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

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…

your sample open quick access

should do a replace string??

$envWinDir\Logs\Software

to

$env:WinDir\Logs\Software

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))
  •   + 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: (:slight_smile: [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: (:slight_smile: [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: (:slight_smile: [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().

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

	[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