January 1, 2012 at 12:00 am #5151
by tyleracrowder at 2012-09-28 00:23:44
I am trying to create a simple script to copy files from one directory on a server to another directory on a Windows 2008 server. – ex: xcopy c:\scripts\*.* c:\destination
If I launch a normal dos prompt window and use robocopy or xcopy, the files copy just fine.
However, whenever I use Powershell to initiate the copy, I get an access denied error on the destination directory. I've tried using copy-item, robocopy, and xcopy with Powershell. The user I'm logged in as is a member of the Administrators group. The administrators group has full rights to the destination directory. If I grant the user explicit rights to the folder, the copy is successful through Powershell. I do not want to have to grant the user explicit rights, as this is a test for a much larger automation script that will be run as a startup script.
by poshoholic at 2012-09-28 07:40:21
Sounds to me like you need to launch PowerShell in an elevated prompt so that your token has the administrative rights it should have via the Administrators group membership.
by tyleracrowder at 2012-09-28 08:13:03
[quote="poshoholic"]Sounds to me like you need to launch PowerShell in an elevated prompt so that your token has the administrative rights it should have via the Administrators group membership.[/quote]
This script will be run as part of a Windows Startup Script during boot, not in an prompt window. Is it possible to set the elevated access programatically?
by poshoholic at 2012-09-28 08:28:50
Are you using Group Policy to launch this as a logon script?
by tyleracrowder at 2012-09-28 09:15:01
[quote="poshoholic"]Are you using Group Policy to launch this as a logon script?[/quote]
Yes, just to clarify, it is a Windows Startup Script, not a Login script. We use the script for a bunch of automation to initially configure the Windows server upon boot-up, including copying some files.
by poshoholic at 2012-09-28 12:09:12
You can't elevate a script from within that script. Some searching around seems to indicate you should try scheduling the execution of the script or invoking the script using the Windows startup options (Registry) in order to get it to run with elevation. I haven't personally tried any of this though. This indicates it's not so much a PowerShell problem (it affects other scripts too, such as vbs, etc), but a logon script challenge you're trying to work out.
You must be logged in to reply to this topic.