r/PowerShell • u/No_Concentrate2648 • Mar 09 '26
Question Access to the path C:\Temp is denied
Hi all,
I'm trying to run a Powershell script to export all my AD groups + the creation dates / times and for that I found the next Powershell script:
Get-ADGroup -Filter * -Properties whenCreated, whenChanged |
Select Name, DistinguishedName, GroupScope, GroupCategory,
@{Name='Created';Expression={$_.whenCreated}},
@{Name='Modified';Expression={$_.whenChanged}},
ObjectGUID |
Export-Csv -Path C:\Temp -NoTypeInformationThe issue is that when I try to run this script, it says the following:
Export-Csv : Access to the path 'C:\Temp' is denied.
At line:6 char:1
+ Export-Csv -Path C:\Temp -NoTypeInformation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Export-Csv], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommandFor this I checked the permissions and I have full access to the folder + I'm a domain admin and I started Powershell as an admin as well. Replacing C:\Temp with downloads or desktop didn't work for me either.
Does anyone know what I can check or what I am doing wrong in this case?
2
Upvotes
23
u/korewarp Mar 09 '26
Looks like you're trying to save your CSV as the temp folder. Path should be 'C:\Temp\groups.csv'
5
u/BlackV Mar 09 '26 edited Mar 10 '26
Glad you have a fix
I'd also have a look at
$env:tempinstead asc:\tempis not a default folder-7
u/HumbleSpend8716 Mar 10 '26
Good thing you’re a domain admin, wouldn’t want someone in that role who can read a fucking error message