How to read SQL Agent logs using Windows PowerShell

Prerequisite: SQL Management Studio needs to be installed [sourcecode language=”powershell”] [System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.Smo’) | Out-Null $Sql = New-Object (‘Microsoft.SqlServer.Management.Smo.Server'<strong>)”<SQL Instance Name>”</strong> $SQLAgent = $Sql.JobServer $SQLAgent.ReadErrorLog() | format-list * [/sourcecode]  

Continue reading

Powershell Functions do not return single element arrays

I came across an interesting problem today that a function I wrote to return all SCCM primary sites worked at work but did not work at home. the difference between 2 SCCM environments is that I only have 1 single SCCM site in my home environment comparing to large multi-tier SCCM infrastructure at work. after some investigation I found out this common issue with Powershell when comes to returning arrays from a function. For example: The first function foo should returns a single element arraylist, and the variable it returned has the same type as the type of the only

Continue reading
%d bloggers like this: