我正在开发一个自动化工具,我必须自动完成服务包升级的自动化。
从命令提示符执行无提示安装命令
param([string]$servername,[string]$path)
#param([string]$instance)
#$path1="d:\sysdba\"
#$path2= $path1 "+" $path
Try
{
$SqlQuery = "SELECT @@SERVICENAME"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $Servername; Database = master; Integrated Security = SSPI;"
write-host $SqlConnection.ConnectionString
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$instancename = $DataSet.Tables[0].rows[0].Column1
Write-Host $instancename
#$DataSet.Tables[0] | out-file "C:\temp\version.csv"
#$command=$path1
write-host $servername
write-host $instancename
$arg1="/instancename=$instancename"
$arg2= "/quiet"
$arg3= "/IACCEPTSQLSERVERLICENSETERMS=TRUE"
write-host $arg1
write-host $instancename
# D:\sysdba\SQLServer2008R2SP2-KB2630458-x64-ENU.exe /instancename=SQLINST /quiet /IACCEPTSQLSERVERLICENSETERMS=”TRUE” | Out-File d:\sysdba\test.txt
& $path $arg1 $arg2 $arg3
Write-Host "Success."
Write-Host "true" | out-file "D:\temp\installation.csv"
}
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
}
代码工作得很好,我的问题是如何知道安装失败需要通过重启,我看到的选项是来自Microsoft的summary.txt
文件,但我需要继续检查。
有没有办法可以检查安装过程的完成情况?