For developers: Powershell scripts that might be helpful

Here I want to share some Powershell scripts that I use constantly and has proven to be useful (for me) specially if you have more than one instance of Sitecore in your machine.

Clean Sitecore logs from your machine

Push-Location "C:\inetpub\wwwroot"
Get-ChildItem .\ -Include logs -Recurse | foreach ($_) { Remove-Item $_.fullname -Include "*.txt", "*.log" -Recurse -Verbose -ErrorAction SilentlyContinue }

Restart all Solr Services

Restart-Service -DisplayName "Solr*" -Verbose

Restart all Sitecore services

Restart-Service -DisplayName "Sitecore *" -Verbose

Kill all w3wp processes

Stop-Process -Name "w3wp" -Force -Verbose

Clean all obj, bin folders from a Helix solution

$srcFolder = "C:\Git\example.com\src"

Push-Location "$srcFolder\Project"
Get-ChildItem .\ -Include bin,obj -Recurse | foreach ($_) { Remove-item $_.fullname -Force -Recurse -Verbose }

Push-Location "$srcFolder\Feature"
Get-ChildItem .\ -Include bin,obj -Recurse | foreach ($_) { Remove-item $_.fullname -Force -Recurse -Verbose }

Push-Location "$srcFolder\Foundation"
Get-ChildItem .\ -Include bin,obj -Recurse | foreach ($_) { Remove-item $_.fullname -Force -Recurse -Verbose }

Write-Host -NoNewLine 'Done. Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');

That’s all for this article.

Credits

Photo by Julie Molliver on Unsplash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s