I just have to blog this little gem. Every now and then I would be running a PowerShell script, I’d get an error but I wouldn’t get anything useful from the default error message besides the line number.
 

Little Gem

cls
$error[0] | fl -force

Sample

For example, this is an error I would get from the PowerShell console or PowerShell ISE:

Exception calling "Create" with "0" argument(s): "Create failed for 
JobSchedule 'Every 3rd Friday 6AM'. "
At C:UsersAdministratorDropboxPackt Draft PS ScriptsCh0315 - 
Schedule a SQL Server Job - Every 3rd Friday at 6AM.ps1:63 char:1
+ $jobsched.Create();
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FailedOperationException

A sample result that I would get from this little gem, which tells me *exactly* my issue, so I don’t have to dig any further or pull up Profiler. Cool!!

Exception             : System.Management.Automation.MethodInvocationException: Exception calling "Create" 
with "0" argument(s): "Create failed for JobSchedule 'Every 3rd Friday 6AM'. " 
---> Microsoft.SqlServer.Management.Smo.FailedOperationException: 
Create failed for JobSchedule 'Every 3rd Friday 6AM'.  
---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: 
An exception occurred while executing a Transact-SQL statement or batch. 
---> System.Data.SqlClient.SqlException: The schedule for this job is invalid (reason: @freq_recurrence_factor must be at least 1.). 
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean 
 catchException)
    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteScalar(String sqlCommand)
    --- End of inner exception stack trace ---
    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteScalar(String sqlCommand)
    at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteScalar(StringCollection sqlCommands)
    at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteScalar(StringCollection query)
    at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ExecuteNonQuery(StringCollection queries, Boolean includeDbContext)
    at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImplFinish(StringCollection createQuery, ScriptingPreferences sp)
    at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
    --- End of inner exception stack trace ---
    at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
    at CallSite.Target(Closure , CallSite , Object )
    --- End of inner exception stack trace ---
    at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, String methodName, Int32 numArgs)
    at CallSite.Target(Closure , CallSite , Object )
    at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
    at System.Management.Automation.Interpreter.DynamicInstruction`2.Run(InterpretedFrame frame)
    at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : FailedOperationException
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at , C:UsersAdministratorDropboxPackt Draft PS ScriptsCh0315 - Schedule a SQL Server Job - Every 3rd Friday at 6AM.ps1: line 63
PipelineIterationInfo : {}
PSMessageDetails      : 
VN:F [1.9.22_1171]
Rating: 9.5/10 (6 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Getting More Information About Your PowerShell Error, 9.5 out of 10 based on 6 ratings  
Be Sociable, Share!
  • Tweet