Home:ALL Converter>Out-File in Powershell script fails to be updated or created when called through batch script?

Out-File in Powershell script fails to be updated or created when called through batch script?

Ask Time:2019-07-31T18:59:45         Author:ITSUUUUUH

Json Formatter

I have a PowerShell script that logs certain information to a file via the Out-File command:

"text to be logged" | Out-File $logFile -Append

When the PowerShell script is run directly, the log file is created/updated without any problems. This PowerShell script is called through a batch script (due to a tool I am utilizing that only accepts batch scripts as input) through the following command:

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File """"%powerShellScriptPath%"""" """"%argOne%"""" """"%argTwo%""""' -Verb RunAs}";

The command I am implementing above is based on the implementation found in this answer.

When called through the batch script, the log file never gets created/updated. The PowerShell script performs all of its duties behind the scenes without issues, it simply fails to create the log file or populate it with data...

Author:ITSUUUUUH,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57289221/out-file-in-powershell-script-fails-to-be-updated-or-created-when-called-through
yy