0

I have a PowerShell script that runs exactly the way I want interactively; creating two log files: one is a csv for graphing the output later, and the other is a basic status log, such as:

Opening database connection at 01/27/2015 09:11:47
Site analysis started.
Successfully recorded site metrics.

My scheduled task runs the PowerShell successfully, and commits all my entries to a SQL DB, but my csv and txt log are not completed.

I am using Write-Output and Out-File

My logs are set as such:

$LogFilePath = $("L:\Scripts\Metrics\Site_Analysis.csv")
$StatusLogFilePath = $("L:\Scripts\Metrics\Site_Analysis_Status.log")

The PowerShell script runs in:

C:\Scripts\

I really don't want to create a batch file that simply outputs everything such as:

batchfile.bat > file.log

since the desired output is very specific, and I don't want verbose output.

I found this, https://stackoverflow.com/questions/25311489/scheduled-powershell-task-wont-write-to-file

but even with the log files set to the same directory, it still did not output.

Thanks.

Edit @ 9:22AM - 1/27/2015:

Please note that all csv and log file output is historical (output is appended).

  • Try to give Full Permission on Scripts folder to the account that is running the script. – Amal Hashim Jan 27 '15 at 14:38
  • Thanks for the reply. I gave full permissions on the directory and recursively to the child items, to the account running the PowerShell Script, but it did not resolve the issue. – raredesign Jan 27 '15 at 14:52
  • Ok, in all fairness, I don't know if I should delete this question until I figure out what is going on now. My scheduled task was working, but now it is not, so I will need to fix this first. – raredesign Jan 27 '15 at 15:51
  • Can I delete this question somehow? I don't want it to confuse anyone. It turns out that the scheduled task path had quotes that were an invalid character type. I had copy/paste it from the command prompt and I just noticed they looked different than a normal ". It works now that I replaced them. The log files output fine too! I apologize for the misstep. – raredesign Jan 27 '15 at 15:59
  • raredesign: you can post the above comment as an answer. It might help other people who are in similar situation. – Amal Hashim Jan 27 '15 at 16:00
0

I don't want it to confuse anyone, but it turns out that the scheduled task path had quotes that were an invalid character type. I had copy/paste it from the command prompt and I just noticed they looked different than a normal ". It works now that I replaced them. The log files output fine too! Even though it was a misstep, hopefully this helps someone in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.