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: Scripts:
- ../../WindowsPowerShell/Functions/ImportCoreFunctions.ps1 - ../../WindowsPowerShell/Functions/ImportCoreFunctions.ps1
- ../../WindowsPowerShell/Functions/Update-ServiceConfig.ps1 - ../../WindowsPowerShell/Functions/Update-ServiceConfig.ps1
- ../../WindowsPowerShell/Functions/SQLServerForAOAG.ps1
- ../../WindowsPowerShell/Functions/Failover-Cluster.ps1 - ../../WindowsPowerShell/Functions/Failover-Cluster.ps1
Commands: Commands:
- Name: Install-FailoverClusterPrerequisites - Name: Install-FailoverClusterPrerequisites
Arguments: {} Arguments: {}
- Name: Enable-TrustedHosts
Arguments: {}
- Name: Update-ServiceConfig - Name: Update-ServiceConfig
Arguments: Arguments:
Name: Murano Agent 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 { process {
trap { trap {
Write-LogError $_ -EntireObject &$TrapHandler
break
} }
$ErrorActionPreference = 'Stop'
Write-Log "--> New-FailoverClusterSharedFolder" Write-Log "--> New-FailoverClusterSharedFolder"
Write-Log "Creating shared folder for Failover Cluster ..." Write-Log "Creating shared folder for Failover Cluster ..."
@ -139,12 +136,9 @@ function New-FailoverCluster {
} }
process { process {
trap { trap {
Write-LogError $_ -EntireObject &$TrapHandler
break
} }
$ErrorActionPreference = 'Stop'
Write-Log "ClusterNodes: $($ClusterNodes -join ', ')" Write-Log "ClusterNodes: $($ClusterNodes -join ', ')"
if ($Credential -eq $null) { if ($Credential -eq $null) {

View File

@ -1,5 +1,6 @@
Import-Module CoreFunctions -Force Import-Module CoreFunctions -Force
function Show-InvocationInfo { function Show-InvocationInfo {
param ( param (
$Invocation, $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 # Usage example for Show-InvocationInfo
@ -40,6 +56,9 @@ function MyFunction {
Show-InvocationInfo $MyInvocation -End Show-InvocationInfo $MyInvocation -End
} }
process { process {
trap {
&$TrapHandler
}
# Main code here # Main code here
} }
} }

View File

@ -25,38 +25,49 @@ Function Install-SqlServer {
[Switch] $MixedModeAuth = $false, [Switch] $MixedModeAuth = $false,
[Switch] $UpdateEnabled = $false [Switch] $UpdateEnabled = $false
) )
begin {
Show-InvocationInfo $MyInvocation
}
end {
Show-InvocationInfo $MyInvocation -End
}
process {
trap {
&$TrapHandler
}
if ($SetupRoot -eq '') { if ($SetupRoot -eq '') {
if ($MuranoFileShare -eq '') {
$MuranoFileShare = [Environment]::GetEnvironmentVariable('MuranoFileShare')
if ($MuranoFileShare -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') if ($SAPassword -ne '') {
} $ExtraOptions += @{'SAPWD' = $SAPassword}
#$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 (-not $UpdateEnabled) {
$ExtraOptions += @{'UpdateEnabled' = $false}
}
Show-Environment
New-SqlServer -SetupRoot $SetupRoot -ExtraOptions $ExtraOptions
} }
if ($SAPassword -ne '') {
$ExtraOptions += @{'SAPWD' = $SAPassword}
}
if (-not $UpdateEnabled) {
$ExtraOptions += @{'UpdateEnabled' = $false}
}
Show-Environment
New-SqlServer -SetupRoot $SetupRoot -ExtraOptions $ExtraOptions
} }

View File

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

View File

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

View File

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

View File

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