English 中文(简体)
2008年:如何获得“Messages”表格(管理室产出)和权力hell
原标题:SQL Server 2008: how to get the "Messages" tab (in Management Studio) output with powershell

I am using invoke-sqlcmd to manage my databases, it works fine. I save the output of the "Results" tab in Management Studio to a log file.

当我做一个<条码>BACKUP DATABASE时,产出就在“Messages”表格上进行,我希望在日志中予以节省。

是否有办法获得这一产出? (或2008年SQ服务器的一个表格,储存了后备进展和成果?)

服务器2008年记录含有一些东西,但并非像“Messages”表一样。

最佳回答

Invoke-Sqlcmd does not display messages, such as the output of PRINT statements, unless you specify the Windows PowerShell -Verbose common parameter. For example:

Invoke-Sqlcmd -Query "PRINT N abc ;" -Verbose

http://msdn.microsoft.com/en-us/library/cc281720.aspx” rel=“nofollow”

问题回答

帮助某人的工作实例:

$ps = [PowerShell]::Create()
[ref]$e = New-Object System.Management.Automation.Runspaces.PSSnapInException
$ps.Runspace.RunspaceConfiguration.AddPSSnapIn( "SqlServerCmdletSnapin100", $e ) | Out-Null
$ps.AddCommand( "Invoke-Sqlcmd" ).AddParameter( "Verbose" ).AddParameter( "ServerInstance", "localhostSQLEXPRESS2K8" ).AddParameter( "Query", "BACKUP DATABASE xxx TO DISK = N c:	mpxxx.bak  WITH FORMAT, STATS = 10" )
$ps.Invoke()
$ps.Streams.Verbose | % { $_.Message} | Out-File c:	mpps002.txt
cat c:	mpps002.txt




相关问题
Performance impact of indexed view in MS SQL Server 2008

Does anyone have experience with using indexed view in MS SQL Server 2008? I am trying to find out how does indexed view affect performance of insert / update statements, that are adding / updating ...

Lock Escalation - What s happening here?

While altering a table (removing a column) in SQL Server 2008, I clicked the Generate Change Script button and I noticed that the change script it generated drops the column, says "go" and then runs ...

Round to nearest 5 in SQL Server

I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$ select FineAmount from tickets Thanks

热门标签