2014-09-30 66 views
1

我試圖從我的服務器上覆制一些文件到工作站。如果我將$Foldername更改爲C:\,則該過程正常工作。但是,如果我以這種方式保留代碼,即如果我決定將文件複製到C:\Program Files\Interrogator訪問被拒絕 - 混淆了COPY-ITEM

我得到這個錯誤:

Copy-Item : Access to the path 'C:\Program Files\Interrogator\Setup Instructions.txt' is denied. 
At C:\Users\coduy\Desktop\Copy2Test.ps1:20 char:10 
+ Copy-Item <<<< -Path \\10.10.0.10\DeploymentShare\Applications\JDE-Interrogator\* -Destination $Foldername 
    + CategoryInfo   : PermissionDenied: (\\10.10.0.10\De...nstructions.txt:FileInfo) [Copy-Item], Unauthorized 
    AccessException 
    + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand 

我可以看到,訪問被拒絕,但爲什麼呢?我沒有共享任何文件夾,如果我決定要複製到發現,其他用戶也有類似的問題C:\C:\Program Files

$net = New-Object -comobject Wscript.Network 
    $net.MapNetworkDrive("Z:","\\10.13.0.10\DeploymentShare\Applications\JDE Interrogator",0,"mydomain\coduy","P0kroy$") 

    $uncServer = "\\10.10.0.10\" 
    $uncFullPath = "\\10.13.0.10\DeploymentShare\Applications\JDE Interrogator" 
    $username = "coduy" 
    $password = "password" 
    $Foldername="C:\Program Files\Interrogator" 


    net use $uncServer $password /USER:$username 
    try 
    { 

    mkdir C:\'Program Files'\Interrogator 
    Copy-Item -Path \\10.10.0.10\DeploymentShare\Applications\JDE-Interrogator\* -Destination $Foldername 


    } 
    finally { 
    net use $uncServer /delete 
    } 
+0

該文件是否已經存在於目的地,如果它是隻讀的,您是否有權修改該文件? – TheMadTechnician 2014-09-30 17:28:09

+0

這是一個權限問題,更適合[SuperUser](http://superuser.com)或[服務器故障](http://serverfault.com)。 – Raf 2014-10-01 08:33:28

+0

如何將它移動到其他頁面? – Okrx 2014-10-01 08:44:42

回答

0

不應有任何區別,這似乎是一個合理的答案:

Windows Vista and above default to not allowing non-administrative users to write to the `%PROGRAMFILES% folder. This means that you're not going to be allowed to copy the files there; you're also not going to be able to save them after doing your find/replace operation.

You can write them to your user documents folder (%USERPROFILE%\Documents) folder instead, if that will work for you.

share|edit answered Dec 23 '12 at 6:32

Ken White 74.5k770140