Difference between revisions of "PowerShell Examples"

Jump to navigation Jump to search
616 bytes added ,  14:07, 6 January 2012
→‎MySQL: Added "Test for NULL"
(Added "SSH Client")
(→‎MySQL: Added "Test for NULL")
Line 301: Line 301:
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand("USE $database", $conn)
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand("USE $database", $conn)
</source>
</source>
=== Test for NULL ===
In order to be able to test for a NULL value in a set of results from a query, you need to compare against a specific DB NULL value.  Otherwise you'll get an error similar to...
<code> Error: "Cannot convert the "0" value of type "System.Int32" to type "System.DBNull" </code>
So to correctly test, use the following...
<source lang="powershell">
if ([System.DBNull]::Value.Equals($db_query_result)) {
    Write-Host "Result is NULL"
}
</source>
The above was sourced from http://blogs.technet.com/b/industry_insiders/archive/2008/09/15/testing-for-database-null-values-from-powershell.aspx


== Scheduling ==
== Scheduling ==

Navigation menu