У меня нет проблем, используя скрипт с именем test.ps1
add-pssnapin SqlServerCmdletSnapin100
get-host
$sql = "selects * from syscomments"
$server = ""
$database = ""
$username = ""
$password = ""
try {
Invoke-Sqlcmd -Query $sql -ServerInstance $server -database $database -QueryTimeout 65535 -ErrorAction 'Stop' -username $username -password $password
} catch {
"error when running sql $sql"
Write-Host($error)
}
И вывод
PS C:\> .\test.ps1
Name : ConsoleHost
Version : 2.0
InstanceId : 9ac019da-97bd-45d1-bfa5-65fb4d376dc6
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-AU
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
error when running sql selects * from syscomments
Incorrect syntax near '*'.
какие входные параметры вы используете, используете PowerShell 1 или 2