2014-10-06 100 views
1

我在PowerShell中寫過功能,它刪除IIS中的虛擬文件夾,刪除物理路徑,將文件解壓縮到文件夾,並在舊名稱的IIS中創建虛擬路徑。步驟2中的問題。腳本嘗試刪除文件和文件夾。IIS服務器如何正確刪除文件夾

... 
get-childitem ($pathToIIs + "*") -recurse | remove-item -Force -recurse 
... 

Powershell的拋出錯誤:

Cannot remove item C:\inetpub\test\css: The directory is not empty. + CategoryInfo : WriteError: (css:DirectoryInfo) [Remove-Item], I OException + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell .Commands.RemoveItemCommand + PSComputerName : test.cloudapp.net

如果理解正確,停止和啓動IIS它的壞主意。那麼如何解決這個錯誤?

回答

0

MUST停止IIS,以便能夠消除由IIS鎖定的文件:

... 
iisreset /stop 
get-childitem ($pathToIIs + "*") -recurse | remove-item -Force -recurse 
iisreset /start 
... 

停止IIS會明顯並暫時防止您的服務器網頁服務。