DEV Community

redhcp
redhcp

Posted on

Clean temporal files from site from IIS Powershell

this is for ALL sites

#invoke-command -computername "HOSTNAME" -scriptblock {iisreset /STOP}
#invoke-command -computername "HOSTNAME" -scriptblock {iisreset /START} ; Start-WebSite $args[0]
Enter fullscreen mode Exit fullscreen mode

this is for ONE site

Import-Module WebAdministration
$serverName = "COMPUTERNAME"      #name VM
$siteName = "ELA_Client" #name site
$block = {Stop-WebSite $args[0]};  
$session = New-PSSession -ComputerName $serverName

#stop site
Invoke-Command -Session $session -ScriptBlock $block -ArgumentList $siteName

#remove data path
Invoke-Command -Session $session -ScriptBlock {Get-ChildItem โ€“Path "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\*\" | Remove-Item -Recurse -Force }

#start site 
$block = {Start-WebSite $args[0]};  
Invoke-Command -Session $session -ScriptBlock $block -ArgumentList $siteName

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Some comments have been hidden by the post's author - find out more