This should be absuredly easy but I keep running into a brick wall. I am running a Powershell script which performs an audit of my tasks and saves the result to a CSV. I keep getting a permissions fault though and I can not figure out what I am missing.
Here is my code:
Get-ScheduledTask |
Where State -ne "Disabled" |
Get-ScheduledTaskInfo |
Select TaskName,TaskPath,LastRunTime, LastTaskResult,NextRunTime,NumberofMissedRuns |
Where { $_.TaskName -like "test_*"} |
Export-Csv -NoTypeInformation -Path C:\temp\scheduled_tasks_audit
Here is what I am getting in response:
Export-Csv : Access to the path 'C:\temp\scheduled_tasks_audit' is denied.
At C:\temp\scheduled_tasks_audit\example_task_audit.ps1:6 char:5
+ Export-Csv -NoTypeInformation -Path C:\temp\scheduled_tasks_audit
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Export-Csv], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand
I checked the user that Powershell was running under using:
[Environment]::UserName
And made sure that the account had full permissions for the destination folder but I'm still getting a access denied error.
I am running Windows Server 2012 R2 and Powershell 4.0