Skip to content

Instantly share code, notes, and snippets.

@blachniet
Last active December 19, 2015 14:09
Show Gist options
  • Select an option

  • Save blachniet/5966819 to your computer and use it in GitHub Desktop.

Select an option

Save blachniet/5966819 to your computer and use it in GitHub Desktop.
Loads the sqlps module if the "Invoke-Sqlcmd" cmdlet does not exist.
function Import-Module-SqlServer{
if (!(Get-Command Invoke-Sqlcmd -ErrorAction SilentlyContinue)){
Write-Host "Loading SQL Server PowerShell module..."
Import-Module "sqlps" -DisableNameChecking
Write-Host " Done"
}
}

Loads the sqlps module if the "Invoke-Sqlcmd" cmdlet does not exist. This is the suggested method for loading the module according to MSDN docs. You can download the module installer from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment