Skip to content

Instantly share code, notes, and snippets.

@AshFlaw
Last active April 6, 2018 14:45
Show Gist options
  • Save AshFlaw/02634d520dc6900f8a9d202bd63bb8e5 to your computer and use it in GitHub Desktop.
Save AshFlaw/02634d520dc6900f8a9d202bd63bb8e5 to your computer and use it in GitHub Desktop.
function Test-SQLTableExists
{
param ($Instance,$Database,$TableName)
$Return = $SQL = $dataTable = $null
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'$TableName'"
$dataTable = Invoke-Sqlcmd2 -ServerInstance $Instance -Database $Database -Query $sql
if ($dataTable) {$return = $true}
else {$return = $false}
$Return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment