IIS服务器如何正确删除文件夹
问题描述:
我在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它的坏主意。那么如何解决这个错误?
答
您MUST停止IIS,以便能够消除由IIS锁定的文件:
...
iisreset /stop
get-childitem ($pathToIIs + "*") -recurse | remove-item -Force -recurse
iisreset /start
...
停止IIS会明显并暂时防止您的服务器网页服务。