5
votes

I'm trying to redirect console output from a TFS command to a file with the following command:

witadmin listfields /collection:blahblah:8080/tfs/TPC > TFSfields.txt

but I get an error:

"Access to the path 'C:\....\TFSfields.txt is denied"

and also further down:

OpenError: (:) [Out-File], UnauthorizedAccess

I'm fairly new to PowerShell, so I'm not sure how I could not have access to create a file in a directory on my own machine. I'm assuming I'm missing something simple. When I run the command without redirecting output, it outputs what I expect to the screen.

Did you run Powershell as Administrator? - Tony Hinkle
To run as admin, right-click on the powershell icon on the taskbar and choose 'Run as administrator'. Lack of admin privileges is most probably the issue - jithinpt
Running as Administrator fixed the issue. I really don't like that. If the user that is currently logged in has permission to create a file in a directory, then why would powershell, run by said user, not have permission to create a file in that directory? - Dave Novelli
You should not have to 'Run As Administrator' if the user running PowerShell has access to create files in the target folder. Be more specific about the path you are getting an error with, or specify a full path for your output file. Maybe try witadmin listfields /collection:blahblah:8080/tfs/TPC > "$env:USERPROFILE\Desktop\TFSfields.txt" That will create the file on the current user's desktop. - TheMadTechnician
@TheMadTechnician You're right. I didn't realize Program Files (x86) is protected directory. Is that new in Windows 8? At any rate, running PowerShell as administrator solved the problem. Thanks! - Dave Novelli