found this article.
http://www.mssqltips.com/sql-server-tip-category/81/PowerShell/
http://www.mssqltips.com/sqlservertip/2911/using-powershell-to-access-event-logs-for-sql-server/?utm_source=dailynewsletter&utm_medium=email&utm_content=headline&utm_campaign=20130917
substract commands:
about logs:
Get-EventLog -LogName "application" -Message "*error*" -After "April 01, 2013 4:52:31 PM" | Where-Object {$_.source -like "*SQL*"} | format-list TimeGenerated, Source, Message
Get-EventLog -LogName "system" -newest 20 | export-csv c:\tools\top_20_events.csv
Get-EventLog -LogName "system" | Where-Object {$_.source -like "*SQL*"} | select-Object Index,entrytype, message | out-file C:\tools\sql_server_logs.txt
$begintime = Get-Date 10/31/2016
$endtime = Get-Date 11/13/2016
Get-EventLog -LogName System -ComputerName kdcwspsdbstg01 -EntryType Error,Warning -After $begintime -before $endtime
http://www.mssqltips.com/sql-server-tip-category/81/PowerShell/
http://www.mssqltips.com/sqlservertip/2911/using-powershell-to-access-event-logs-for-sql-server/?utm_source=dailynewsletter&utm_medium=email&utm_content=headline&utm_campaign=20130917
substract commands:
about logs:
Get-EventLog -listGet-EventLog -LogName "application" | Where-Object {$_.source -like "*SQL*"} | select-Object Index,entrytype, message
Get-EventLog -LogName "application" -Message "*error*" -After "April 01, 2013 4:52:31 PM" | Where-Object {$_.source -like "*SQL*"} | format-list TimeGenerated, Source, Message
Get-EventLog -LogName "system" -newest 20 | export-csv c:\tools\top_20_events.csv
Get-EventLog -LogName "system" | Where-Object {$_.source -like "*SQL*"} | select-Object Index,entrytype, message | out-file C:\tools\sql_server_logs.txt
$begintime = Get-Date 10/31/2016
$endtime = Get-Date 11/13/2016
Get-EventLog -LogName System -ComputerName kdcwspsdbstg01 -EntryType Error,Warning -After $begintime -before $endtime
Clear-eventlog -Logname "Windows PowerShell"
About service:
Get-Service -computername SERVERNAMEGet-Service -Name MSSQLSERVERGet-service | Where-Object {$_.status -eq "Running"}Stop-Service -Name SqlserveragentStop-Service -displayname *SQL* -whatifGet-service -displayname *SQL* | Where-object {$_.status -eq "running"} |Stop-Service -confirmget-wmiobject win32_service | where {$_.Name -eq "sqlserveragent"} set-service sqlserveragent -startup automaticset-service -name sqlserveragent -DisplayName "Microsoft Sql Server Agent" set-service -name Sqlserveragent -description "SQL Server Agent Service to handle agent related tasks." set-service sqlserveragent -status runningAbout process:
Get-Process -computername MANVENDRAGet-Process *SQL*Get-Process -id $pidGet-Process sqlservr | format-list * Get-Process | Select-Object name,fileversion,productversion,companyGet-Process | sort CPU Get-Process | sort idStop-process ID 3276 Stop-process -processname sqlagentStart-Process notepad Start-process eventvwr Start-Process powershell -verb runas
Comments
Post a Comment