Powershell Function to Get SQL Server’s Errorlog Path

This is a repost of Ed Wilson the ScriptingGuy’s awesome function:

#Get the SQL Error Log Directory on a Server
Function Get-ErrorLogPath 
{ 
  <# 
   .Synopsis 
    Returns the path to the SQL Error Log 
   .Description 
    This function returns the path to the SQL Error Log 
   .Example 
    Get-ErrorLogPath 
    Returns the path to the SQL Error Log on default instance of SQL on 
    local machine 
   .Example 
    Get-ErrorLogPath -SQLServer SQL1 
    Returns the path to the SQL Error Log on default instance of SQL on 
    a SQL server named SQL1 
   .Parameter SQLServer 
    The name and instance of SQL Server 
   .Notes 
    NAME:  Get-ErrorLogPath 
    AUTHOR: ed wilson, msft 
    LASTEDIT: 05/27/2011 11:34:59 
    KEYWORDS: Databases, SQL Server, Add-Type 
    HSG: HSG-5-31-11 
   .Link 
     http://www.ScriptingGuys.com 
 #Requires -Version 2.0 
 #> 
 Param([string]$SQLServer = "(local)") 
 try { 
    add-type -AssemblyName "Microsoft.SqlServer.Smo,  
    Version=10.0.0.0, 
    Culture=neutral,  
    PublicKeyToken=89845dcd8080cc91" -EA Stop } 
 
 catch {add-type -AssemblyName "Microsoft.SqlServer.Smo"} 
 $server = new-object ("Microsoft.SqlServer.Management.Smo.Server") $SQLServer 
 $server.ErrorLogPath 
} #end function Get-ErrorLogPath
Advertisements

About Nick Xu

Not a DBA anymore
This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s