Overclock.net banner

1 - 9 of 9 Posts

·
Registered
Joined
·
2,326 Posts
Discussion Starter #1
Hey guys, I have a question related to Powershell Scripting. I am admittedly very new to this, so bear with me, as I've only just started googling this topic yesterday.

So, I currently have a script, that I'm running on a Server 2008 R2 environment, that pulls all inactive users from Active Directory and lists their last logon timestamp. Then exports that data to a CSV file. It works exactly how I would like. However, If another user logs in under their own credentials to run that script, they get "Access Denied" to the CSV filename that the script tries to create.

Is there anything I can do or change about the script so that any user can run this script and have the file be created without this issue?

Any help would be appreciated.
 

·
Registered
Joined
·
2,309 Posts
It means the user running the task doesn't have permission to write to the file or directory you do.

There are few ways to go about doing this but quickly it would just mean changing the location of the csv to a place where your underling has access
 

·
Registered
Joined
·
2,326 Posts
Discussion Starter #3
It means the user running the task doesn't have permission to write to the file or directory you do.

There are few ways to go about doing this but quickly it would just mean changing the location of the csv to a place where your underling has access
Ok, that makes sense. What's weird with that, though, is that myself and the other user testing this script with me both have admin access.

Would it possibly be better to set the file location to somewhere like the public documents folder in that case?
 

·
Moderator
Joined
·
13,090 Posts
Might need to see the relevant parts of the script that generate the CSV file and call out it's file name.


Or at the minimum, where is the CSV file being stored?
1) on a network location somewhere
2) in the logged in user's directory
3) on the local machine in a secure folder that needs admin rights


Without much information to go on, I can only assume it tries to overwrite the same CSV file when it is run from another user, but the CSV file is locked by the first user it was run on, or was run by an admin account and created in an admin folder or something.
 

·
Registered
Joined
·
2,326 Posts
Discussion Starter #5
Might need to see the relevant parts of the script that generate the CSV file and call out it's file name.


Or at the minimum, where is the CSV file being stored?
1) on a network location somewhere
2) in the logged in user's directory
3) on the local machine in a secure folder that needs admin rights


Without much information to go on, I can only assume it tries to overwrite the same CSV file when it is run from another user, but the CSV file is locked by the first user it was run on, or was run by an admin account and created in an admin folder or something.
I'll try to answer as best I can and help shed some light on the needed details.

The CSV file is set to be created in the "Users\Public\Documents" folder (I have changed it from the previous reply to this thread).
 

·
Registered
Joined
·
2,326 Posts
Discussion Starter #6
Just an update. Moving the Script to the Public Documents folder, and telling the script to create the CSV file within that same folder answered my issue. I am now able to have other users run that script without getting the "Access Denied" error from before.

Thank you guys for letting me bounce this off of you to get the info that helped.
 

·
Moderator
Joined
·
13,090 Posts
Just an update. Moving the Script to the Public Documents folder, and telling the script to create the CSV file within that same folder answered my issue. I am now able to have other users run that script without getting the "Access Denied" error from before.

Thank you guys for letting me bounce this off of you to get the info that helped.
Glad you figured it out, just our of curiosity, where were you saving the CSV file before?
 

·
Registered
Joined
·
100 Posts
The user may have admin rights, but that doesn't mean the application is able to use them without running elevated ( command prompt, for instance, when running batch files still needs to be elevated otherwise you run into issues )...

You can either run elevated, or you can change the permissions to write to the directory using the security tab and add the normal user group to allowed instead of admin.

Some folders will allow reading / writing by default - I think the documents folder is one of these folders.
 

·
Registered
Joined
·
2,326 Posts
Discussion Starter #9
Glad you figured it out, just our of curiosity, where were you saving the CSV file before?
I discovered that I was originally saving the CSV file to my own user documents folder. Which is what was causing the other user to get the "Access Denied" message.
 
1 - 9 of 9 Posts
Top