通过静默安装在SQL Server上安装Service Pack。 代码工作没有参数,但参数ts不起作用
没有参数的代码
param([string]$servername)
param([string]$instance)
$path1="D:\sysdba\SQLServer2008R2SP2-KB2630458-x64-ENU.exe"
Try
{
$SqlQuery = "SELECT * from dbo.BlockingInfoOutput;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $Servername; Database = master; Integrated Security = SSPI;"
write-host $SqlConnection.ConnectionString
$command=$path1
write-host $servername
write-host $instance
$arg1="/instancename=" + $instance
$arg2= "/quiet"
$arg3= "/IACCEPTSQLSERVERLICENSETERMS=TRUE"
write-host $arg1
write-host $instance
# D:\sysdba\SQLServer2008R2SP2-KB2630458-x64-ENU.exe /instancename=SQLINST /quiet /IACCEPTSQLSERVERLICENSETERMS=”TRUE” | Out-File d:\sysdba\test.txt
write-host $path1 $arg1 $arg2 $arg3
Write-Host "Success."
}
Catch
{ Write-Host -BackgroundColor Red -ForegroundColor White" Fail"
$errText = $Error[0].ToString()
if ($errText.Contains("network-related"))
{Write-Host "Connection Error. Check server name, port, firewall."}
Write-Host $errText
continue
}
带参数的代码
& $path1 $arg1 $arg2 $arg3
这是我使用的连接但不起作用?
任何帮助,请
答案 0 :(得分:1)
我没有用exe和参数测试命令。但试试这个:
Start-Process -FilePath $PathToExe-ArgumentList "/quiet" -Wait