I have a list of files to copy to/from different locations. Unfortunately, one of them has spaces in the subdirectory. Not all of them have subdirectories, and not all have spaces. This is a directory I can't rename because it's the VM directory and renaming it would involve removing and reinstalling the whole VM. This is what the script looks like.

$vDrive = "V:\VM - USA02xxxx\VM-USA02xxxx.vhd"
$vDriveToLoc = "G:\"

Copy-Item $vDrive $vDriveToLoc

The error message is Copy-Item: Access to the path 'V:\VM - USA02xxxx\VM-USA02xxxxx.vhd' is denied.

I'm administrator and have full control to the file/folders so that isn't the issue. It copies the files in the other directories fine.

I've tried replacing the double quotes with single quotes and it doesn't fix it. I've tried, with double quotes, to add back-ticks in front of each space. It didn't work.

I know that when I do this at the powerShell command line, it works to cd V:\ then cd "VM - USA02xxxx", but I can't do this programmatically for a long list of files/directories. Any ideas?

I saw this link but I'm not sure it would apply here: http://social.technet.microsoft.com/Forums/scriptcenter/en-US/71ec2cae-b126-4a4d-9622-169aa7c6b0ad/trying-to-copy-folderfiles-using-powershell?forum=winserverpowershell

I tried doing what one guy commented about here but it didn't work: https://stackoverflow.com/questions/3868342/running-an-exe-using-powershell-from-a-directory-with-spaces-in-it

  • 1
    is your powershell instance running as admin? default windows permissions require admin to write to the root folder of the drive. – Frank Thomas Jan 16 '14 at 21:24
  • What happens when you throw quotes around the variables. Copy-Item "$vDrive" "$vDriveToLoc" – Knuckle-Dragger Jan 17 '14 at 9:38
  • @FrankThomas - I am logged in as admin. I also added the following to the powershell command line because of something I read somewhere: Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned" – Michele Jan 17 '14 at 14:21
  • @Knuckle-Dragger - I tried adding the double quotes and it still gave the error message. Good idea, though. Any other ideas?? :) – Michele Jan 17 '14 at 14:35
  • Well this is interesting. I added a file junk.txt to V:\ drive and added it to list of files to copy. When it got to the file, the error message was "Copy-Item:Cannot find path 'v:\junk.txt' because it does not exist." I checked permissions of the directory and file and it's full control to me, System, and Administrators. – Michele Jan 17 '14 at 14:56

Here is a registry key to enable mapped drive across the split UAC token. I think that is why V: drive isn't accessible from your admin script.

New-ItemProperty -Path "registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "EnableLinkedConnections" -Value 1 -PropertyType "DWord"

This problem occurs because UAC treats members of the Administrators group as standard users. Therefore, network shares that are mapped by logon scripts are shared with the standard user access token instead of with the full administrator access token.


The alternative answer is to net use v: \\etc\etc in your script to re-map each time it runs.


Thanks for the ideas guys! I was trying some things and added myself to both from and to directories with full control and it worked! I'm not sure why I needed that since I'm in Administrators group.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.