diff --git a/SCCM/Get-SCCMClientLog.ps1 b/SCCM/Get-SCCMClientLog.ps1 new file mode 100644 index 0000000..0066e09 --- /dev/null +++ b/SCCM/Get-SCCMClientLog.ps1 @@ -0,0 +1,102 @@ +Function Get-SccmClientLog ($ComputerName,$LogName) { + try { + Write-Debug "Initiating the $($MyInvocation.MyCommand.Name) function..."; + $output_properties = @{'ComputerName'=$ComputerName;'Log'=$LogName} + + if ($LogName -ne 'setup') { + $sPath = "\\$ComputerName\admin$\ccmlogs"; + $aLogData = @(); + $aDir = Get-ChildItem $sPath | where { !$_.PsIsContainer }; + foreach ($sLog in $aDir) { + if ($sLog -match $LogName) { + $aLogData += Get-Content "$sPath\$sLog"; + }##endif + }##endif + if ($LogName -eq 'smsts') { + if (Test-Path "$sPath\SMSTSLog\smsts.log") { + $aLogData += Get-Content "$sPath\SMSTSLog\smsts.log"; + }##endif + }##endif + if ($LogName -eq 'smsts') { + $log_data = Format-SccmClientLogData $aLogData | Format-SccmClientSmsTsLog; + $output_properties.Add('LogData',$log_data) + New-Object –TypeName PSObject –Prop $output_properties + } else { + $log_data = Format-SccmClientLogData $aLogData; + $output_properties.Add('LogData',$log_data) + New-Object –TypeName PSObject –Prop $output_properties + }##endif + } else { + $sPath = "\\$ComputerName\admin$\ccmsetup\logs"; + $aLogData = Get-Content "$sPath\ccmsetup.log"; + $log_data = Format-SccmClientLogData $aLogData; + $output_properties.Add('LogData',$log_data) + New-Object –TypeName PSObject –Prop $output_properties + }##endif + } catch [System.Exception] { + Write-Warning "$($MyInvocation.MyCommand.Name): $($_.Exception.Message)"; + return $false; + }##endtry +}##endfunction + +##Removes all the SMS-specific stuff like [LOG, component, etc +##Get-SccmClientLog passes all potential output to this cmdlet +Filter Format-SccmClientLogData ($aLogData) { + try { + Write-Debug "Initiating the $($MyInvocation.MyCommand.Name) function..."; + $aFilteredLog = @(); + foreach ($sLine in $aLogData) { + $reLine = ([regex]'