Reputation: 163
Maybe I'm just blind, but I'm trying to run the following command and have tried -recurse, -force, -confirm:$false
and nothing is working. Keeps telling me that there are children and asking if I want to remove them. I'm going to be using this script on multiple remote servers so can't have any prompts.
Is there no way to remove a virtual directory silently? If the code below won't work, anyone else have a tip on how I can cleanup IIS to not have this virtual directory under my default web site?
I took the suggested edits, but am still not having much luck with any of the methods I've used to suppress messages in other situations. I'm starting to think one does not exist for this situation which is a terrible shame for those of us who manage dozens of IIS servers, etc.
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"
}
Upvotes: 3
Views: 4453
Reputation: 489
If you are using newer versions of Powershell you can use Remove_Item.
Remove-Item "IIS:\Sites\Default Web Site\LIT" -Force -Recurse
I tested this using PowerShell version 4.0.
Upvotes: 4
Reputation: 163
I ended up giving up. I did find a way to use a wrapper, but it seemed way too complicated, so I just went back to running this particular step as good old fashioned CMD.
Article I found about the wrapper: http://stevenmaglio.blogspot.com/2014/10/powershell-virtualdirectory-wrappers.html
What I used:
C:\Windows\SysWOW64\inetsrv\appcmd delete vdir /vdir.name:"Default Web Site"/LIT
Upvotes: 2