Skip to content

Instantly share code, notes, and snippets.

@SoulOfUniverse
Created July 13, 2021 19:18
Show Gist options
  • Save SoulOfUniverse/0462aacd966b61369d4293cd07b2559c to your computer and use it in GitHub Desktop.
Save SoulOfUniverse/0462aacd966b61369d4293cd07b2559c to your computer and use it in GitHub Desktop.
Sitecore Powershell Get Sitecore Logs Remotely
<#
Set-ExecutionPolicy RemoteSigned
#>
Import-Module -Name SPE
$session = New-ScriptSession -Username "Remoting" -Password "test" -ConnectionUri https://sitecore.instance.local
$jobId = Invoke-RemoteScript -ScriptBlock {
$filename = "log*"
Write-Verbose ("Started at " + [System.DateTime]::Now)
$files = Get-ChildItem $SitecoreLogFolder
$files | sort LastWriteTime | select -last 10 #| Get-Content -Tail 100
Write-Verbose "#### next ####" -ForegroundColor Yellow
$files | Where-Object {$_.Name -like $filename} | sort LastWriteTime | select -last 1 | Get-Content -Tail 300
Write-Verbose ("Finished at " + [System.DateTime]::Now)
} -AsJob -Session $session -Verbose
Wait-RemoteScriptSession -Session $session -Id $jobId -Delay 1 -Verbose
Stop-ScriptSession -Session $session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment