powershell Powershell安装脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Powershell安装脚本相关的知识,希望对你有一定的参考价值。

<#
.SYNOPSIS
   Install SQL2008R2 Server
.DESCRIPTION
   use Switches to install SQL Server Features easy and silently
.PARAMETER instanceName
   Name of SQL Instance
.PARAMETER useGerman
   Install German Version of SQL Server (Managementstudio)
.PARAMETER installOnly
   Use this parameter to only install Managementstudio or SQL Engine
.EXAMPLE
   Install-SQL2008R2.ps1 -installOnly SQLEngine -useGerman
.Notes
    File Name   : Install-SQL2008R2.ps1
    Author      : Robert Rajakone 
    Date        : 05. September 2013    
#>


param(
	[string] $instanceName="SQL2008R2",
	[switch] $useGermanVersion,
    
    [ValidateSet('SQLEngine', 'ManagementStudio')]
    [string] $installOnly
)


#Changing to germany regional settings
if($useGermanVersion){ Start-Process -Wait -ArgumentList @("/c", "\\DOS-Scripts\change_locale_de-DE.bat") -FilePath cmd.exe }

#Switching Installer depending on Language
$Installer = "\\software\SQL Server Express Edition 2008R2\SQLEXPRADV_x64_ENU\setup.exe"
if($useGermanVersion){ $Installer = "\\software\SQL Server Express Edition 2008R2\SQLEXPRADV_x64_DEU.exe" }

# Gathering Features
$Features = @()
if($installOnly){
    if($installOnly.equals("SQLEngine") ){
        $Features +="SQLEngine"
        $Features +="FullText"

    }
    
    if($installOnly.equals("ManagementStudio") ){
        $Features +="SSMS"
    }
}else{
        $Features +="SSMS"
        $Features +="RS"
        $Features +="SQLEngine"
        $Features +="FullText"
}

$FeatureList = $Features -join ","
$Args = @(
            "/ACTION=Install"
			"/IACCEPTSQLSERVERLICENSETERMS"
			"/ERRORREPORTING=0"
			"/FEATURES=$FeatureList"
			"/INSTANCENAME=$instanceName"
            "/QS"
            "/SAPWD=secret-sa-password"
            "/SECURITYMODE=SQL"
            "/ADDCURRENTUSERASSQLADMIN"
            "/RSINSTALLMODE=`"FilesOnlyMode`""
		)


#Check for Drive D
if(gwmi win32_volume -Filter "DriveType=3 AND DriveLetter='D:'"){
    Write-Host "D-Drive found. Installing on D"
    $Args +="/INSTANCEDIR=`"D:\Programme\SQL2008R2\INSTANCE_SQL2008R2`""
}

#Do Installing
Write-Host "Using the folling Parameter for installing ..."
$Args | %{ Write-Host $_ }

Start-Process -Wait -FilePath $Installer -ArgumentList $Args

#Changing back to swiss regional settings
if($useGermanVersion){ Start-Process -Wait -ArgumentList @("/c", "\\DOS-Scripts\change_locale_de-CH.bat") -FilePath cmd.exe }

Write-Host "Installation finish!"

以上是关于powershell Powershell安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

powershell 用于使用Chocolatey安装开发机器的PowerShell脚本。

PowerShell 批量执行所有主机通过脚本安装软件

PowerShell 批量执行所有主机通过脚本安装软件