For developers: Helpful PowerShell scripts
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.
comments powered by Disqus