0
我在尝试使用PowerShell脚本以静默方式安装SQL Server 2008 R2。 安装后,我需要验证安装是否成功。 有没有什么办法可以检查sqlsetup.log
文件中退出代码是否成功安装?如何验证SQL Server 2008 R2的成功安装
以下是代码,我目前使用: -
# Read current directory
$ScriptPath = $MyInvocation.MyCommand.Path
$ParentDir = Split-Path $scriptpath
#Read Config file from current directory
$ConfigFile = $ParentDir + '\ConfigurationFile.ini'
Write-Host $ConfigFile
#Holds base setup from current directory
$SetupFile=$ParentDir + '\setup.exe'
Write-Host $SetupFile
$SP3SetupFile=$ParentDir + '\SQLServer2008R2_SP3\Setup.exe'
Write-Host $SP3SetupFile
#Start of the log file
$Start="========================================================================================"
$Start | Out-File $env:temp\InstallSQL2008R2_log.txt -append
#Printsd the current date and time in log file
$Date=Get-Date
$Date | Out-File $env:temp\InstallSQL2008R2_log.txt -append
#Starting with the SQL base installation
$InstallBaseSQL="Installing SQL Server 2008 R2"
$InstallBaseSQL | Out-File $env:temp\InstallSQL2008R2_log.txt -append
#Installs SQL Server 2008 R2 Standard Edition
& "$SetupFile" /ConfigurationFile="$ConfigFile"
#Checks whether properly installed
$ExistString = Select-String -Path "$env:temp\SqlSetup*.log" -Pattern "Setup closed with exit code: 0x00000000"
if($ExistString)
{
$SuccessStatus = "Installation of SQL Server 2008 R2 completed"
$SuccessStatus | Out-File $env:temp\InstallSQL2008R2_log.txt -append
#write-host "Installation of SQL Server 2008 R2 completed"
#out-file $env:temp\InstallSQL2008R2_log.txt -append
# $log.name | out-file $C:\FileContainingString.txt -append
}
else
{
$failStatus = "Installation couldn't complete, for more details please check sqlsetup.txt in temp folder"
$FailStatus | Out-File $env:temp\InstallSQL2008R2_log.txt -append
}
#Installing sql patch
$InstallSQLSP3="Installing SQL Server 2008 R2 SP3"
$InstallSQLSP3 | Out-File $env:temp\InstallSQL2008R2_log.txt -append
#Install SQL Server 2008 R2 SP3 Patch
& "$SP3SetupFile" /instancename=MSSQLSERVER /quiet
#Completion Message
$PatchComplete="Installation of SQL Server 2008 R2 SP3 completed3"
$PatchComplete | Out-File $env:temp\InstallSQL2008R2_log.txt -append
$End="========================================================================================"
$End | Out-File $env:temp\InstallSQL2008R2_log.txt -append
不能说我见过任何人保存每个输出到一个新的变量,然后将其保存到一个文件。为什么不直接将字符串输入到“Out-File”?无论如何,而不是检查日志文件,你可以检查[这篇文章](http://stackoverflow.com/questions/3257328/detecting-if-sql-server-2008-is-installed?rq=1)的注册表标志,但错误代码“0x00000000”(日志的第二行)意味着没有错误。 –