0
我已經創建了一個PowerShell腳本,用於將文件複製到目錄,腳本,首先創建文件夾或強制新文件夾事件(如果存在)。然後從另一個位置複製一個目錄。複製完成後,我需要根據用戶給出的值執行腳本來複制正確的Web配置文件。我遇到的問題是我可以複製這些文件,但是當我嘗試複製正確的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")