Question about Powershell Scripting - Overclock.net - An Overclocking Community

Forum Jump: 

Question about Powershell Scripting

 
Thread Tools
post #1 of 9 (permalink) Old 01-09-2019, 07:05 AM - Thread Starter
New to Overclock.net
 
Destrto's Avatar
 
Join Date: Apr 2013
Location: Richardson, TX
Posts: 2,254
Rep: 80 (Unique: 63)
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.

EK Club XCrossXFire ClubX
-OCN Water Cooling Club-
Destrto
(13 items)
CPU
AMD FX-8370
Motherboard
MSI 990FXA-Gaming
GPU
AMD PowerColor RX 580
RAM
G.Skill - Ripjaws X Series 16Gb
RAM
G.Skill - Ripjaws X Series 16 GB
Hard Drive
Samsung 850 500Gb
Hard Drive
Seagate 3 Tb
Power Supply
Raidmax Vampire 800 Watt
Cooling
EK-Suprema​cy MX CPU ​Block
Cooling
XSPC 240mm​ Radiator
Cooling
XSPC 240mm​ Radiator
Cooling
EK-XRES 140 DDC 3.2 PWM Elite
Case
HBT Gravity6
▲ hide details ▲
Destrto is offline  
Sponsored Links
Advertisement
 
post #2 of 9 (permalink) Old 01-09-2019, 07:10 AM
New to Overclock.net
 
doritos93's Avatar
 
Join Date: Oct 2009
Location: Montreal
Posts: 2,309
Rep: 119 (Unique: 84)
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



doritos93 is offline  
post #3 of 9 (permalink) Old 01-09-2019, 07:12 AM - Thread Starter
New to Overclock.net
 
Destrto's Avatar
 
Join Date: Apr 2013
Location: Richardson, TX
Posts: 2,254
Rep: 80 (Unique: 63)
Quote: Originally Posted by doritos93 View Post
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?

EK Club XCrossXFire ClubX
-OCN Water Cooling Club-
Destrto
(13 items)
CPU
AMD FX-8370
Motherboard
MSI 990FXA-Gaming
GPU
AMD PowerColor RX 580
RAM
G.Skill - Ripjaws X Series 16Gb
RAM
G.Skill - Ripjaws X Series 16 GB
Hard Drive
Samsung 850 500Gb
Hard Drive
Seagate 3 Tb
Power Supply
Raidmax Vampire 800 Watt
Cooling
EK-Suprema​cy MX CPU ​Block
Cooling
XSPC 240mm​ Radiator
Cooling
XSPC 240mm​ Radiator
Cooling
EK-XRES 140 DDC 3.2 PWM Elite
Case
HBT Gravity6
▲ hide details ▲
Destrto is offline  
Sponsored Links
Advertisement
 
post #4 of 9 (permalink) Old 01-09-2019, 07:13 AM
Rust Buckets for Days
 
axipher's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 13,080
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.



Spoiler!


axipher is offline  
post #5 of 9 (permalink) Old 01-09-2019, 07:27 AM - Thread Starter
New to Overclock.net
 
Destrto's Avatar
 
Join Date: Apr 2013
Location: Richardson, TX
Posts: 2,254
Rep: 80 (Unique: 63)
Quote: Originally Posted by axipher View Post
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).

EK Club XCrossXFire ClubX
-OCN Water Cooling Club-
Destrto
(13 items)
CPU
AMD FX-8370
Motherboard
MSI 990FXA-Gaming
GPU
AMD PowerColor RX 580
RAM
G.Skill - Ripjaws X Series 16Gb
RAM
G.Skill - Ripjaws X Series 16 GB
Hard Drive
Samsung 850 500Gb
Hard Drive
Seagate 3 Tb
Power Supply
Raidmax Vampire 800 Watt
Cooling
EK-Suprema​cy MX CPU ​Block
Cooling
XSPC 240mm​ Radiator
Cooling
XSPC 240mm​ Radiator
Cooling
EK-XRES 140 DDC 3.2 PWM Elite
Case
HBT Gravity6
▲ hide details ▲
Destrto is offline  
post #6 of 9 (permalink) Old 01-09-2019, 08:31 AM - Thread Starter
New to Overclock.net
 
Destrto's Avatar
 
Join Date: Apr 2013
Location: Richardson, TX
Posts: 2,254
Rep: 80 (Unique: 63)
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.

EK Club XCrossXFire ClubX
-OCN Water Cooling Club-
Destrto
(13 items)
CPU
AMD FX-8370
Motherboard
MSI 990FXA-Gaming
GPU
AMD PowerColor RX 580
RAM
G.Skill - Ripjaws X Series 16Gb
RAM
G.Skill - Ripjaws X Series 16 GB
Hard Drive
Samsung 850 500Gb
Hard Drive
Seagate 3 Tb
Power Supply
Raidmax Vampire 800 Watt
Cooling
EK-Suprema​cy MX CPU ​Block
Cooling
XSPC 240mm​ Radiator
Cooling
XSPC 240mm​ Radiator
Cooling
EK-XRES 140 DDC 3.2 PWM Elite
Case
HBT Gravity6
▲ hide details ▲
Destrto is offline  
post #7 of 9 (permalink) Old 01-09-2019, 02:55 PM
Rust Buckets for Days
 
axipher's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 13,080
Quote: Originally Posted by Destrto View Post
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?



Spoiler!


axipher is offline  
post #8 of 9 (permalink) Old 01-09-2019, 08:12 PM
New to Overclock.net
 
Join Date: Jun 2018
Location: Hendersonville, NC
Posts: 100
Rep: 0
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.
Acecool is offline  
post #9 of 9 (permalink) Old 01-10-2019, 11:29 AM - Thread Starter
New to Overclock.net
 
Destrto's Avatar
 
Join Date: Apr 2013
Location: Richardson, TX
Posts: 2,254
Rep: 80 (Unique: 63)
Quote: Originally Posted by axipher View Post
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.

EK Club XCrossXFire ClubX
-OCN Water Cooling Club-
Destrto
(13 items)
CPU
AMD FX-8370
Motherboard
MSI 990FXA-Gaming
GPU
AMD PowerColor RX 580
RAM
G.Skill - Ripjaws X Series 16Gb
RAM
G.Skill - Ripjaws X Series 16 GB
Hard Drive
Samsung 850 500Gb
Hard Drive
Seagate 3 Tb
Power Supply
Raidmax Vampire 800 Watt
Cooling
EK-Suprema​cy MX CPU ​Block
Cooling
XSPC 240mm​ Radiator
Cooling
XSPC 240mm​ Radiator
Cooling
EK-XRES 140 DDC 3.2 PWM Elite
Case
HBT Gravity6
▲ hide details ▲
Destrto is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off