Solved

Powershell write to text file owned by s/o else

Posted on 2010-09-13
11
539 Views
Last Modified: 2012-08-14
Hello,

I'm writing a powershell script that writes log infos to a text file using the "Add-Content" command. All works fine as long as I use the same windows user. As soon as another user starts the script, the log file can't be appended any more (access denied). Both users are in the local Administrators group and looking into the effective rights, the second user has full permissions.

Any idea?

__Leo
0
Comment
Question by:LeoKurz
  • 4
  • 4
  • 2
11 Comments
 
LVL 37

Expert Comment

by:Neil Russell
Comment Utility
Where is the output file stored?
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
where is this file? is it in the users personal directories? maybe something like uac might be stopping it. have u tried aa a test write to \temp?
0
 

Author Comment

by:LeoKurz
Comment Utility
Hi,

I created a directory c:\bu-script

__Leo
0
 
LVL 37

Expert Comment

by:Neil Russell
Comment Utility
can BOTH users edit the text file that is created by using notepad.exe ?
A simple test
0
 

Author Comment

by:LeoKurz
Comment Utility
No, using Notepad, the userer who is *not* the owner of the file can not save it.

__Leo
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:LeoKurz
Comment Utility
Did another test, opened notepad with a right-click -> Open as Administrator, opened the file, modified it and was able to save the modified file. So I think it has to do with uac. This is weered! I have all permissions and still can't write! Anyone any idea how to get this solved w/o having to run the sript with elevated privileges? I *do* have all fs permissions.

__Leo
0
 
LVL 37

Expert Comment

by:Neil Russell
Comment Utility
Then your issue is purely one of ownership. As the user who can NOT save the file, can you open the file security tab and post here a screen shot?
Or jus double check that both have READ/WRITE to the file & folder
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
0
 

Author Comment

by:LeoKurz
Comment Utility
Filesystem rights are all there. It seems that with uac, a user can not write into another file owned by another user, even though all the file permissions are in place. This is crab! I changed the ownership to the local administrator group, no help.

__Leo
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
Comment Utility
Then you will have to elevate or switch off UAC I think to get the desired rights. UAC is a pain in the A**!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This article will help you understand what HashTables are and how to use them in PowerShell.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now