.Net对象的PowerShell事件不按顺序
我正在使用Sql Server SMO和Powershell脚本编写SQL脚本的执行脚本。 我们发现了两个问题: Powershell的事件处理按顺序处理 在所有事件都被处理之前,控制权被返回到调用脚本(这是有道理的,因为它们应该是asynchronous的)。 鉴于这个脚本: Add-Type -AssemblyName "Microsoft.SqlServer.SMO, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" | Out-Null Add-Type -AssemblyName "Microsoft.SqlServer.ConnectionInfo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" | Out-Null (Get-Date -format "dd-MMM-yyyy HH:mm:ss.fff") + ": Starting Script" | Out-File -FilePath $sqlOutputFilename -Append $serverConnection = New-Object ('Microsoft.SqlServer.Management.Common.ServerConnection') "FTS-DEVSERVER", "SA", "avid4uin)*" $serverSMO = new-object ('Microsoft.SqlServer.Management.Smo.Server') $serverConnection $sqlOutputFilename = "output.log" $serverMessage = { (Get-Date […]