PowerShell scripts updated.

* Error traps added.
* Tracing added.
* Enable-TrustedHosts added to another YAML.
* JSON files updated.

Change-Id: I76414217fb8cb77575b8b36499b5dfb952adeb5f
This commit is contained in:
Dmitry Teselkin 2013-08-08 14:43:22 +04:00
parent 7aee81ca7c
commit e73918da57
15 changed files with 158 additions and 70 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,16 @@
Scripts:
- ../../WindowsPowerShell/Functions/ImportCoreFunctions.ps1
- ../../WindowsPowerShell/Functions/Update-ServiceConfig.ps1
- ../../WindowsPowerShell/Functions/SQLServerForAOAG.ps1
- ../../WindowsPowerShell/Functions/Failover-Cluster.ps1
Commands:
- Name: Install-FailoverClusterPrerequisites
Arguments: {}
- Name: Enable-TrustedHosts
Arguments: {}
- Name: Update-ServiceConfig
Arguments:
Name: Murano Agent

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -71,12 +71,9 @@ function New-FailoverClusterSharedFolder {
}
process {
trap {
Write-LogError $_ -EntireObject
break
&$TrapHandler
}
$ErrorActionPreference = 'Stop'
Write-Log "--> New-FailoverClusterSharedFolder"
Write-Log "Creating shared folder for Failover Cluster ..."
@ -139,11 +136,8 @@ function New-FailoverCluster {
}
process {
trap {
Write-LogError $_ -EntireObject
break
&$TrapHandler
}
$ErrorActionPreference = 'Stop'
Write-Log "ClusterNodes: $($ClusterNodes -join ', ')"

View File

@ -1,5 +1,6 @@
Import-Module CoreFunctions -Force
function Show-InvocationInfo {
param (
$Invocation,
@ -24,6 +25,21 @@ function Show-InvocationInfo {
}
}
$TrapHandler = {
Write-LogError @("<exception>", $_) -EntireObject
Write-LogError "</exception>"
break
}
trap {
&$TrapHandler
}
$ErrorActionPreference = 'Stop'
<#
# Usage example for Show-InvocationInfo
@ -40,6 +56,9 @@ function MyFunction {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
# Main code here
}
}

View File

@ -25,38 +25,49 @@ Function Install-SqlServer {
[Switch] $MixedModeAuth = $false,
[Switch] $UpdateEnabled = $false
)
begin {
Show-InvocationInfo $MyInvocation
}
end {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ($SetupRoot -eq '') {
if ($MuranoFileShare -eq '') {
$MuranoFileShare = [Environment]::GetEnvironmentVariable('MuranoFileShare')
if ($SetupRoot -eq '') {
if ($MuranoFileShare -eq '') {
throw("Unable to find MuranoFileShare path.")
$MuranoFileShare = [Environment]::GetEnvironmentVariable('MuranoFileShare')
if ($MuranoFileShare -eq '') {
throw("Unable to find MuranoFileShare path.")
}
}
$SetupRoot = [IO.Path]::Combine($MuranoFileShare, 'Prerequisites\SQL Server\2012')
}
#$MixedModeAuthSwitch = ConvertTo-Boolean $MixedModeAuth
$ExtraOptions = @{}
if ($MixedModeAuth -eq $true) {
$ExtraOptions += @{'SECURITYMODE' = 'SQL'}
if ($SAPassword -eq '') {
throw("SAPassword must be set when MixedModeAuth is requisted!")
}
}
$SetupRoot = [IO.Path]::Combine($MuranoFileShare, 'Prerequisites\SQL Server\2012')
}
#$MixedModeAuthSwitch = ConvertTo-Boolean $MixedModeAuth
$ExtraOptions = @{}
if ($MixedModeAuth -eq $true) {
$ExtraOptions += @{'SECURITYMODE' = 'SQL'}
if ($SAPassword -eq '') {
throw("SAPassword must be set when MixedModeAuth is requisted!")
if ($SAPassword -ne '') {
$ExtraOptions += @{'SAPWD' = $SAPassword}
}
}
if ($SAPassword -ne '') {
$ExtraOptions += @{'SAPWD' = $SAPassword}
}
if (-not $UpdateEnabled) {
$ExtraOptions += @{'UpdateEnabled' = $false}
if (-not $UpdateEnabled) {
$ExtraOptions += @{'UpdateEnabled' = $false}
}
Show-Environment
New-SqlServer -SetupRoot $SetupRoot -ExtraOptions $ExtraOptions
}
Show-Environment
New-SqlServer -SetupRoot $SetupRoot -ExtraOptions $ExtraOptions
}

View File

@ -24,24 +24,35 @@ function New-SqlServerSystemAccount {
[String] $PrimaryNode = ' '
)
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
Write-Log "THis function runs on AOAG primary node only."
Write-Log "Exiting."
return
begin {
Show-InvocationInfo $MyInvocation
}
end {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
Write-Log "Installing 'RSAT-AD-PowerShell' ... "
Add-WindowsFeature RSAT-AD-PowerShell
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
Write-Log "THis function runs on AOAG primary node only."
Write-Log "Exiting."
return
}
Import-Module ActiveDirectory
Write-Log "Installing 'RSAT-AD-PowerShell' ... "
Add-WindowsFeature RSAT-AD-PowerShell
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
Import-Module ActiveDirectory
Write-Log "Adding new user ..."
$null = New-ADUser `
-Name $SQLServiceUserName `
-AccountPassword $(ConvertTo-SecureString -String $SQLServiceUserPassword -AsPlainText -Force) `
-Credential $Creds `
-ErrorAction 'Stop'
$Creds = New-Credential -UserName "$DomainName\$UserName" -Password "$UserPassword"
Write-Log "Adding new user ..."
$null = New-ADUser `
-Name $SQLServiceUserName `
-AccountPassword $(ConvertTo-SecureString -String $SQLServiceUserPassword -AsPlainText -Force) `
-Credential $Creds `
-ErrorAction 'Stop'
}
}

View File

@ -10,6 +10,10 @@ function Install-SqlServerPowerShellModule {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ((Get-Module SQLPS -ListAvailable) -ne $null) {
Write-Log "Module SQLSP already installed."
return
@ -79,6 +83,10 @@ function Install-SqlServerForAOAG {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ($MuranoFileShare -eq '') {
$MuranoFileShare = [Environment]::GetEnvironmentVariable('MuranoFileShare')
if ($MuranoFileShare -eq '') {
@ -126,6 +134,10 @@ function Initialize-AlwaysOnAvailabilityGroup {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
$ShareNetworkPath = '\\' + $PrimaryNode + '\' + $ShareName
$DomainAdminAccountCreds = New-Credential `
@ -171,6 +183,10 @@ function New-SharedFolderForAOAG {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ($PrimaryNode.ToLower() -ne ($Env:ComputerName).ToLower()) {
Write-Log "This script runs on primary node only."
Write-Log "Exiting script."
@ -294,6 +310,10 @@ function Initialize-AOAGPrimaryReplica {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
Write-Log "Primary node: '$($PrimaryNode.ToLower())'"
Write-Log "Current node: '$(($Env:ComputerName).ToLower())'"
@ -422,6 +442,10 @@ function Initialize-AOAGSecondaryReplica {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ($PrimaryNode.ToLower() -eq ($Env:ComputerName).ToLower()) {
Write-Log "This function works on any SecondaryNode only."
Write-Log "Exiting."
@ -459,6 +483,10 @@ function Disable-Firewall {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
netsh advfirewall set allprofiles state off
}
}
@ -473,6 +501,10 @@ function Enable-Firewall {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
netsh advfirewall set allprofiles state on
}
}
@ -487,6 +519,10 @@ function Enable-TrustedHosts {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
Set-Item WSMan:\localhost\Client\TrustedHosts -Value '*' -Force
}
}

View File

@ -34,6 +34,10 @@ function Start-PowerShellProcess {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
$StdOut = [IO.Path]::GetTempFileName()
$StdErr = [IO.Path]::GetTempFileName()

View File

@ -14,6 +14,10 @@ function Update-ServiceConfig {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
$ArgumentList = @('config', "`"$Name`"")
if ($RunAsLocalService) {