Remove-WebVirtualDirectory...没有 force/silent 选项?
Remove-WebVirtualDirectory...no force/silent option?
也许我只是瞎了眼,但我正在尝试 运行 以下命令并已尝试 -recurse, -force, -confirm:$false
但没有任何效果。一直告诉我有 children 并询问我是否要删除它们。我将在多个远程服务器上使用此脚本,因此不会有任何提示。
有没有办法静默删除虚拟目录?如果下面的代码不起作用,还有其他人可以告诉我如何清理 IIS 以便在我的默认网站下没有这个虚拟目录吗?
我接受了建议的编辑,但我在其他情况下使用的任何抑制消息的方法仍然不太成功。我开始认为这种情况不存在,这对于我们这些管理数十台 IIS 服务器等的人来说是一种可怕的耻辱。
if (Test-Path "IIS:\Sites\Default Web Site\LIT") {
Remove-WebVirtualDirectory -Site "Default Web Site" -Application "\" -Name LIT
Write-Host " Virtual directory 'LIT' deleted..." -foreground "green"
} else {
Write-Host " Unable to delete 'LIT' virtual directory because it was not found..." -foreground "red"
}
我最终放弃了。我确实找到了一种使用包装器的方法,但它似乎太复杂了,所以我只是回到 运行 这个特定的步骤作为老式的 CMD。
我找到的关于包装器的文章:http://stevenmaglio.blogspot.com/2014/10/powershell-virtualdirectory-wrappers.html
我用过的:
C:\Windows\SysWOW64\inetsrv\appcmd delete vdir /vdir.name:"Default Web Site"/LIT
如果您使用的是较新版本的 Powershell,则可以使用 Remove_Item。
Remove-Item "IIS:\Sites\Default Web Site\LIT" -Force -Recurse
我使用 PowerShell 4.0 版对此进行了测试。
也许我只是瞎了眼,但我正在尝试 运行 以下命令并已尝试 -recurse, -force, -confirm:$false
但没有任何效果。一直告诉我有 children 并询问我是否要删除它们。我将在多个远程服务器上使用此脚本,因此不会有任何提示。
有没有办法静默删除虚拟目录?如果下面的代码不起作用,还有其他人可以告诉我如何清理 IIS 以便在我的默认网站下没有这个虚拟目录吗?
我接受了建议的编辑,但我在其他情况下使用的任何抑制消息的方法仍然不太成功。我开始认为这种情况不存在,这对于我们这些管理数十台 IIS 服务器等的人来说是一种可怕的耻辱。
if (Test-Path "IIS:\Sites\Default Web Site\LIT") {
Remove-WebVirtualDirectory -Site "Default Web Site" -Application "\" -Name LIT
Write-Host " Virtual directory 'LIT' deleted..." -foreground "green"
} else {
Write-Host " Unable to delete 'LIT' virtual directory because it was not found..." -foreground "red"
}
我最终放弃了。我确实找到了一种使用包装器的方法,但它似乎太复杂了,所以我只是回到 运行 这个特定的步骤作为老式的 CMD。
我找到的关于包装器的文章:http://stevenmaglio.blogspot.com/2014/10/powershell-virtualdirectory-wrappers.html
我用过的:
C:\Windows\SysWOW64\inetsrv\appcmd delete vdir /vdir.name:"Default Web Site"/LIT
如果您使用的是较新版本的 Powershell,则可以使用 Remove_Item。
Remove-Item "IIS:\Sites\Default Web Site\LIT" -Force -Recurse
我使用 PowerShell 4.0 版对此进行了测试。