Just started getting my feet wet with interacting with SQL Server using PowerShell and have got this query:
For performing any sql server database operation, using .net framework based objects is my preferred choice mainly because of the reason that I come from C# background. For example:
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand
However, I found that we can also use Invoke-SqlCmd cmdlet available in SqlServerCmdletSnapin100. As:
Add-PSSnapin SqlServerCmdletSnapin100
Set-Location SQLSERVER:\sql\DatabaseInstance\databases\TestDatabase
Invoke-SqlCmd -Query "SELECT * FROM [File]" -User "UserName" -Password "UserPassword"
Wondering, why one should ever go for using Invoke-SqlCmd instead of .net framework based objects?
Was Invoke-SqlCmd made available through PowerShell because some population out there is not familiar with .net framework.
Or
Are there any particular features offered by Invoke-SqlCmd for which we must use it.
Please guide.