christhorsen@xxxxxx wrote:
> How do I add a script block as an event handler?
>
> In C# I can use the following:
>
> SqlConnection conn = new SqlConnection("Data Source=.;Initial
> Catalog=master;INtegrated Security=True");
> conn.FireInfoMessageEventOnUserErrors = true;
> conn.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMessage);
>
> When I tried to run this version:
>
> $SQLConnection = new-object System.Data.SqlClient.SqlConnection("Data
> Source=.;Integrated Security=SSPI;Initial Catalog=master");
> $SQLConnection.Open()
> $handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] {Write-
> Host "Hello World"; Write-Host "$($_)"}
> $SQLConnection += $handler Give this a try:
$SQLConnection.add_InfoMessage($handler)
I just used get-member to try to figure out the syntax, but wasn't able
to actually test it out.
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
Blog:
http://marcoshaw.blogspot.com