Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, December 4, 2017 2:54 PM
This is included in my PowerShell script that I run once a month. I don't think any changes have been made to the directory but the line that is causing the issue is
$HTMLmessage | Out-File ("c:\scripts\reports" + "\report.html")
The file already exists and I have no problem accessing it. Any help is appreciated!
All replies (6)
Monday, December 4, 2017 5:20 PM ✅Answered
Out-File would create the file, if it didn't already exist. And it would overwrite the existing file, unless you used the -append parameter as I.T.Delinquent pointed to.
But, I think your error message indicates that you are lacking the write permission for that file/directory.
wizend
Monday, December 4, 2017 3:26 PM
Since the file already exists, what happens when you add the "-append" parameter to Out-File?
I might be a bit slow on this one but why are you using the "+" sign when point to the file? why not just a full path?
Monday, December 4, 2017 4:26 PM
This script was written before I started and I am still trying to learn this. I will make it all one path and see if any improvement.
Monday, December 4, 2017 6:15 PM
Out-File would create the file, if it didn't already exist. And it would overwrite the existing file, unless you used the -append parameter as I.T.Delinquent pointed to.
But, I think your error message indicates that you are lacking the write permission for that file/directory.
wizend
It is fine that it overwrites. I was suspecting that maybe I no longer have write access. Nothing has changed for the script on my end. I am waiting to hear back from one of our system admins to see if that is the case.
Monday, December 4, 2017 6:33 PM
Is this a scheduled task?
\(ツ)_/
Monday, December 4, 2017 7:52 PM
Is this a scheduled task?
\(ツ)_/
No, it would be smart if we did. We run the scrip at the beginning of the month to use in a monthly report. The issue seemed to be with running the PowerShell as admin. When i did it that way it ran fine. We remote into the server we run the scrip in so I am sure some policy or permission change happened over the last month that we weren't aware of.