DEV Community

redhcp
redhcp

Posted on

4 2

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-ChildItemPath "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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay