24

I am trying to clear up the IISExpress Cache from the powershell. Using this code it complains about the list.

"C:\Program Files (x86)\IIS Express\appcmd.exe" list site /xml | appcmd delete site /in

How can I clear up the sites and the IIS Express cache?

At line:1 char:50
+ "C:\Program Files (x86)\IIS Express\appcmd.exe"  list site /xml | app ...
+                                                  ~~~~
Unexpected token 'list' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
aggie
  • 798
  • 2
  • 8
  • 23

3 Answers3

42

Easy: Just open CMD prompt & Navigate to IIS express - by typing the following

cd "C:\Program Files (x86)\IIS Express\"
//paste & run this 
appcmd.exe list site /xml | appcmd delete site /in

This will delete all the sites, enjoy!

Update for PowerShell Version Thanks to @sibbij

cd "C:\Program Files (x86)\IIS Express\"

run this ./appcmd.exe list site /xml | ./appcmd delete site /in

Transformer
  • 6,963
  • 2
  • 26
  • 52
  • 3
    Copy paste compatible line for Powershell: `./appcmd.exe list site /xml | ./appcmd delete site /in` – sibbl Jan 14 '20 at 12:55
9
  1. Check the Assembly.GetExecutingAssembly().Location property(watch, immediatewindow) when you are debugging and you are stopped at some Breakpoint
  2. you will see a location like below path

%temp%\Temporary ASP.NET Files\vs...\assembly....\YOUR.dll

  1. Check out and delete all folders inside thepath (probably possible after closing IIS express and VS)

%temp%\Temporary ASP.NET Files\

Iman
  • 17,932
  • 6
  • 80
  • 90
  • 1
    Mine wasn't this exact directory, but following your steps I got it. Thank you! – M Kenyon II Apr 21 '20 at 17:23
  • 1
    %temp%\Temporary ASP.NET Files\vs will take you to C:\Users\YOURUSERSNAME\AppData\Local\Temp\Temporary ASP.NET Files\. You don't have to worry about the username or drive letter. – Ahuman May 14 '20 at 01:55
  • 1
    For .net core 2, paste this into the immediate window when stopped at a breakpoint in C#: ?System.Reflection.Assembly.GetExecutingAssembly().Location – sean Dec 03 '20 at 18:21
5

In PowerShell, you need to use the call operator (&) to pass parameters/arguments to an executable.

$appCmd = "C:\Program Files (x86)\IIS Express\appcmd.exe"

$result = Invoke-Command -Command { & $appCmd 'list' 'sites' '/text:SITE.NAME' }

for ($i = 0; $i -lt $result.length; $i++) {
    Invoke-Command -Command { & $appCmd 'delete' 'site'  $result[$i] }
}

Variation from a comment on this page :

Set-Alias appcmd "$env:ProgramFiles\IIS Express\appcmd.exe"

appcmd list site /text:SITE.NAME | % { appcmd delete site $_ }
sodawillow
  • 12,497
  • 4
  • 34
  • 44
  • Thanks for the post, for me this only gets the first site, not all sites. I have IIS express on Wn10 and while, this previous snippet used to work on wn8.1 its not returning the same result on wn10 for me. Anything I can do to check? – aggie Nov 20 '15 at 00:45
  • Do both examples behave the same? – sodawillow Dec 13 '16 at 21:45
  • @sodawillow Please note that the link to "Cleaning up IIS Express Sites" in this post is not working anymore – thomas Feb 10 '21 at 09:48