I have a PS scipt that does have internal reference to an xml config $xmlFilePath = "Config_Device.xml" I need to execute it from System, so using NsudoC in a batch Code: %~dp0NSudoC.exe -U:S -P:E C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file %~dp0\somefile.ps1 But running it I get error from PS that the Config_Device.xml cannot be found Any ideas? sebus
Code: $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition $xmlFilePath = "$scriptPath\Config_Device.xml" other ways https://stackoverflow.com/questions...the-location-of-the-current-powershell-script
$MyInvocation.MyCommand.Definition can still be used but generally it's used for PowerShell 2 and below. In PowerShell 3 the automatic variable $PSScriptRoot was incorporated and is always set to the current scipt/module directory. If using a true UTF-8 formatted XML config file, and not just adding .xml as the extension to a regular .txt file, you will want to use the xml parameter to define the variable: Code: [XML]$XMLFile = Get-Content -Path -XMLFilePath