Link to home
Start Free TrialLog in
Avatar of tolinrome
tolinromeFlag for United States of America

asked on

Powershell - Access to the path denied....

Ok, this is driving me crazy...I opened PS as "Run as administrator" and also as "different user" (which is domain admin), I have local admin rights to my computer and am part of domain admin and I still get access denied trying to save this file to the C drive.
I also ran "Set-ExecutionPolicy RemoteSigned".

Any help?


PS C:\Windows\system32> Get-Process | export-csv -path c:\
export-csv : Access to the path 'C:\' is denied.
At line:1 char:15
+ Get-Process | export-csv -path c:\
+               ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Export-Csv], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You need to add the file name....
Get-Process | export-csv c:\report.csv -NTI

Open in new window

The error is thrown because you can't write a folder, only files. Its text sounds strange and misleading, but indeed it is "correct".
Get-Process | export-csv -path c:\filename.csv  -force

Try  set-executionpolicy unrestricted and see if the above works.
Try his:
Enable "SeTakeOwnershipPrivilege", using the example in this link http://channel9.msdn.com/Forums/Coffeehouse/Powershell-subinacl-ownership-of-directories 

$acl = New-Object System.Security.AccessControl.DirectorySecurity
$acl.SetOwner([System.Security.Principal.NTAccount]'BUILTIN\Administrators')
(Get-Item "C:\").SetAccessControl($acl)
marahman3001,

We already located the primary source of that error message and elaborated in depth about it. It is NOT an access privilege issue.