Overclock.net - An Overclocking Community

Overclock.net - An Overclocking Community (https://www.overclock.net/forum/)
-   Coding and Programming (https://www.overclock.net/forum/142-coding-programming/)
-   -   Question about Powershell Scripting (https://www.overclock.net/forum/142-coding-programming/1717828-question-about-powershell-scripting.html)

Destrto 01-09-2019 07:05 AM

Question about Powershell Scripting
 
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.

doritos93 01-09-2019 07:10 AM

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

Destrto 01-09-2019 07:12 AM

Quote:

Originally Posted by doritos93 (Post 27796400)
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?

axipher 01-09-2019 07:13 AM

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.

Destrto 01-09-2019 07:27 AM

Quote:

Originally Posted by axipher (Post 27796410)
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).

Destrto 01-09-2019 08:31 AM

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.

axipher 01-09-2019 02:55 PM

Quote:

Originally Posted by Destrto (Post 27796580)
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?

Acecool 01-09-2019 08:12 PM

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.

Destrto 01-10-2019 11:29 AM

Quote:

Originally Posted by axipher (Post 27797734)
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.


All times are GMT -7. The time now is 03:55 PM.

Powered by vBulletin® Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
vBulletin Security provided by vBSecurity (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.