2010-07-21 1 views
0

디렉터리, 스크립트에 파일을 복사하기위한 PowerShell 스크립트를 만들었습니다. 먼저 폴더를 만들거나 새 폴더 이벤트가 있으면 강제로 만듭니다. 그런 다음 다른 위치에서 디렉토리를 복사합니다. 복사 한 후 스크립트를 실행하는 사용자가 지정한 값에 따라 올바른 웹 구성을 복사해야합니다. 내가 겪고있는 문제는 파일을 복사 할 수 있지만 올바른 web.config를 복사하려고하면 모든 파일이 읽기 전용으로 설정되고 액세스가 거부되면 스크립트가 실패합니다.디렉터리를 만들거나 복사 할 때 사용 권한이있는 문제

이것은 단순화를 위해 축소 된 스크립트 버전입니다.

$WebApp_Root = 'C:\Documents and Settings\user\Desktop\Dummy.Website' 

$Preview_WebApp_Root = 'c:\applications\Preview\' 

$Choice = read-host("enter 'preview' to deploy to preview, enter Dummy to deploy to Dummy, or enter test to deploy to the test environment") 
if (($Choice -eq 'Preview') -or ($Choice -eq 'preview')) 
{ 
$Choice = 'Preview' 
$Final_WebApp_Root = $Preview_WebApp_Root 
} 

write-host("Releasing Build to " + $Choice +'...') 

write-host("Emptying web folders or creating them if they don't exist... ") 
New-Item $Final_WebApp_Root -type directory -force 

write-host("Copying Files... ") 
Copy-Item $WebApp_Root $Final_WebApp_Root -recurse 

write-host("Copy the correct config file over the top of the dev web config...") 
Copy-Item $Final_WebApp_Root\Config\$Choice\Web.configX $Final_WebApp_Root\web.config 

write-host("Copying correct nhibernate config over") 
Copy-Item $Final_WebApp_Root\Config\$Choice\NHibernate.config $Final_WebApp_Root\NHibernate.config 

write-host("Deployed full application to environment") 

답변

1

읽기 전용 파일을 바꾸려면 -Force 매개 변수를 사용해보십시오. 문서 :

PS> help Copy-Item -Par force 

-Force [<SwitchParameter>] 
    Allows the cmdlet to copy items that cannot otherwise be changed, 
    such as copying over a read-only file or alias. 
관련 문제