Invoke-Sqlcmd unable to run

前端 未结 4 1782
一向
一向 2021-01-04 14:13

I have a PowerShell script that checks the CPU level of the server it is running on, and then if it is above a certain threshold it will run a SQL stored procedure and e-mai

4条回答
  •  青春惊慌失措
    2021-01-04 14:55

    This should help your debugging!

    if (-not (Get-Command Invoke-Sqlcmd -ErrorAction SilentlyContinue)) {
        Write-Error "Unabled to find Invoke-SqlCmd cmdlet"
    }
    
    if (-not (Get-Module -Name SqlServer | Where-Object {$_.ExportedCommands.Count -gt 0})) {
        Write-Error "The SqlServer module is not loaded"
    }
    
    if (-not (Get-Module -ListAvailable | Where-Object Name -eq SqlServer)) {
        Write-Error "Can't find the SqlServer module"
    }
    
    Import-Module SqlServer -ErrorAction Stop
    

提交回复
热议问题