-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from sqlcollaborative/development
v0.8.691
- Loading branch information
Showing
8 changed files
with
455 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,10 @@ | |
{ | ||
<# | ||
.SYNOPSIS | ||
Export SQL Server Availability Groups to a T-SQL file. | ||
Exports SQL Server Availability Groups to a T-SQL file. | ||
.DESCRIPTION | ||
Export SQL Server Availability Groups creation scripts to a T-SQL file. This is a function that is not available in SSMS. | ||
THIS CODE IS PROVIDED "AS IS", WITH NO WARRANTIES. | ||
Exports SQL Server Availability Groups creation scripts to a T-SQL file. This is a function that is not available in SSMS. | ||
.PARAMETER SqlServer | ||
The SQL Server instance name. SQL Server 2012 and above supported. | ||
|
@@ -37,151 +35,151 @@ Confirms each step/line of output | |
.NOTES | ||
Author: Chris Sommer (@cjsommer), cjsommmer.com | ||
dbatools PowerShell module (https://dbatools.io, [email protected]) | ||
dbatools PowerShell module (https://dbatools.io) | ||
Copyright (C) 2016 Chrissy LeMaire | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. | ||
.LINK | ||
https://dbatools.io/Export-DbaAvailabilityGroup | ||
.EXAMPLE | ||
Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath 'C:\temp\availability_group_exports' | ||
Exports all Availability Groups from SQL server "sql2012". Output scripts are witten to the C:\temp\availability_group_exports directory. | ||
Export-DbaAvailabilityGroup -SqlServer sql2012 | ||
Exports all Availability Groups from SQL server "sql2012". Output scripts are written to the Documents\SqlAgExports directory by default. | ||
.EXAMPLE | ||
Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath 'C:\temp\availability_group_exports' -AvailabilityGroups AG1,AG2 | ||
Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath C:\temp\availability_group_exports | ||
Exports Availability Groups AG1 and AG2 from SQL server "sql2012". Output scripts are witten to the C:\temp\availability_group_exports directory. | ||
Exports all Availability Groups from SQL server "sql2012". Output scripts are written to the C:\temp\availability_group_exports directory. | ||
.EXAMPLE | ||
Export-DbaAvailabilityGroup -SqlServer sql2014 -FilePath 'C:\temp\availability_group_exports' -NoClobber | ||
Export-DbaAvailabilityGroup -SqlServer sql2012 -FilePath 'C:\dir with spaces\availability_group_exports' -AvailabilityGroups AG1,AG2 | ||
Exports all Availability Groups from SQL server "sql2014". Output scripts are witten to the C:\temp\availability_group_exports directory. If the export file already exists it will not be overwritten. | ||
Exports Availability Groups AG1 and AG2 from SQL server "sql2012". Output scripts are written to the C:\dir with spaces\availability_group_exports directory. | ||
.LINK | ||
https://dbatools.io/Export-DbaAvailabilityGroup | ||
.EXAMPLE | ||
Export-DbaAvailabilityGroup -SqlServer sql2014 -FilePath C:\temp\availability_group_exports -NoClobber | ||
Exports all Availability Groups from SQL server "sql2014". Output scripts are written to the C:\temp\availability_group_exports directory. If the export file already exists it will not be overwritten. | ||
#> | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
Param ( | ||
[parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[Alias("ServerInstance", "SqlInstance")] | ||
[object[]]$SqlServer, | ||
|
||
[parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[Alias("ServerInstance", "SqlInstance")] | ||
[object[]]$SqlServer, | ||
[System.Management.Automation.PSCredential]$SqlCredential, | ||
|
||
[Alias("OutputLocation", "Path")] | ||
[string]$FilePath, | ||
|
||
[switch]$NoClobber | ||
[string]$FilePath = "$([Environment]::GetFolderPath("MyDocuments"))\SqlAgExport", | ||
[switch]$NoClobber | ||
) | ||
|
||
DynamicParam { if ($SqlServer) { return Get-ParamSqlAvailabilityGroups -SqlServer $SqlServer -SqlCredential $SqlCredential } } | ||
|
||
BEGIN | ||
{ | ||
Write-Output "Beginning Export-DbaAvailabilityGroup on '$SqlServer'" | ||
$AvailabilityGroups = $PSBoundParameters.AvailabilityGroups | ||
|
||
Write-Verbose "Connecting to SqlServer '$SqlServer'" | ||
|
||
try { | ||
$server = Connect-SqlServer -SqlServer $SqlServer -SqlCredential $SqlCredential | ||
} catch { | ||
if ($server.count -eq 1) { | ||
throw $_ | ||
} else { | ||
Write-Warning "Can't connect to $SqlServer. Moving on." | ||
Continue | ||
} | ||
} | ||
} | ||
|
||
PROCESS | ||
{ | ||
# Get all of the Availability Groups and filter if required | ||
$AllAGs = $server.AvailabilityGroups | ||
|
||
if ($AvailabilityGroups) { | ||
Write-Verbose 'Filtering AvailabilityGroups' | ||
$AllAGs = $AllAGs | Where-Object {$_.name -in $AvailabilityGroups} | ||
} | ||
|
||
if ($AllAGs.count -gt 0) { | ||
|
||
# Set and create the OutputLocation if it doesn't exist | ||
$SQLINST = $SQLServer.Replace('\','$') | ||
$OutputLocation = "${FilePath}\${SQLINST}" | ||
|
||
if (!(Test-Path $OutputLocation -PathType Container)) { | ||
New-Item -Path $OutputLocation -ItemType Directory -Force | Out-Null | ||
} | ||
|
||
# Script each Availability Group | ||
foreach ($ag in $AllAGs) { | ||
$AGName = $ag.Name | ||
|
||
# Set the outfile name | ||
if ($AppendDateToOutputFilename.IsPresent) { | ||
$Dttm = (Get-Date -Format 'yyyyMMdd_hhmm') | ||
$OutFile = "${OutputLocation}\${AGname}_${Dttm}.sql" | ||
} else { | ||
$OutFile = "${OutputLocation}\${AGname}.sql" | ||
} | ||
|
||
# Check NoClobber and script out the AG | ||
if ($NoClobber.IsPresent -and (Test-Path -Path $OutFile -PathType Leaf)) { | ||
Write-Warning "OutputFile '$OutFile' already exists. Skipping due to -NoClobber parameter" | ||
} else { | ||
Write-output "Scripting Availability Group [$AGName] on [$SQLServer] to '$OutFile'" | ||
|
||
# Create comment block header for AG script | ||
"/*" | Out-File -FilePath $OutFile -Encoding ASCII -Force | ||
" * Created by dbatools 'Export-DbaAvailabilityGroup' cmdlet on '$(Get-Date)'" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
" * See https://dbatools.io/Export-DbaAvailabilityGroup for more help" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
# Output AG and listener names | ||
" *" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
" * Availability Group Name: $($ag.name)" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
$ag.AvailabilityGroupListeners | % {" * Listener Name: $($_.name)"} | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
# Output all replicas | ||
" *" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
$ag.AvailabilityReplicas | % {" * Replica: $($_.name)"} | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
# Output all databases | ||
" *" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
$ag.AvailabilityDatabases | % {" * Database: $($_.name)"} | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
# $ag | Select-Object -Property * | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
"*/" | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
|
||
# Script the AG | ||
$ag.Script() | Out-File -FilePath $OutFile -Encoding ASCII -Append | ||
} | ||
} | ||
} else { | ||
Write-Output "No Availability Groups detected on '$SqlServer'" | ||
} | ||
} | ||
|
||
END | ||
{ | ||
BEGIN | ||
{ | ||
Write-Output "Beginning Export-DbaAvailabilityGroup on $SqlServer" | ||
$AvailabilityGroups = $PSBoundParameters.AvailabilityGroups | ||
|
||
Write-Verbose "Connecting to SqlServer $SqlServer" | ||
|
||
try | ||
{ | ||
$server = Connect-SqlServer -SqlServer $SqlServer -SqlCredential $SqlCredential | ||
} | ||
catch | ||
{ | ||
Write-Warning "Can't connect to $SqlServer. Moving on." | ||
Continue | ||
} | ||
} | ||
|
||
PROCESS | ||
{ | ||
# Get all of the Availability Groups and filter if required | ||
$allags = $server.AvailabilityGroups | ||
|
||
if ($AvailabilityGroups) | ||
{ | ||
Write-Verbose 'Filtering AvailabilityGroups' | ||
$allags = $allags | Where-Object { $_.name -in $AvailabilityGroups } | ||
} | ||
|
||
if ($allags.count -gt 0) | ||
{ | ||
|
||
# Set and create the OutputLocation if it doesn't exist | ||
$sqlinst = $SQLServer.Replace('\', '$') | ||
$OutputLocation = "$FilePath\$sqlinst" | ||
|
||
if (!(Test-Path $OutputLocation -PathType Container)) | ||
{ | ||
New-Item -Path $OutputLocation -ItemType Directory -Force | Out-Null | ||
} | ||
|
||
# Script each Availability Group | ||
foreach ($ag in $allags) | ||
{ | ||
$agname = $ag.Name | ||
|
||
# Set the outfile name | ||
if ($AppendDateToOutputFilename.IsPresent) | ||
{ | ||
$formatteddate = (Get-Date -Format 'yyyyMMdd_hhmm') | ||
$outfile = "$OutputLocation\${AGname}_${formatteddate}.sql" | ||
} | ||
else | ||
{ | ||
$outfile = "$OutputLocation\$agname.sql" | ||
} | ||
|
||
# Check NoClobber and script out the AG | ||
if ($NoClobber.IsPresent -and (Test-Path -Path $outfile -PathType Leaf)) | ||
{ | ||
Write-Warning "OutputFile $outfile already exists. Skipping due to -NoClobber parameter" | ||
} | ||
else | ||
{ | ||
Write-output "Scripting Availability Group [$agname] on $SQLServer to $outfile" | ||
|
||
# Create comment block header for AG script | ||
"/*" | Out-File -FilePath $outfile -Encoding ASCII -Force | ||
" * Created by dbatools 'Export-DbaAvailabilityGroup' cmdlet on '$(Get-Date)'" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
" * See https://dbatools.io/Export-DbaAvailabilityGroup for more help" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
# Output AG and listener names | ||
" *" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
" * Availability Group Name: $($ag.name)" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
$ag.AvailabilityGroupListeners | ForEach-Object { " * Listener Name: $($_.name)" } | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
# Output all replicas | ||
" *" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
$ag.AvailabilityReplicas | ForEach-Object { " * Replica: $($_.name)" } | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
# Output all databases | ||
" *" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
$ag.AvailabilityDatabases | ForEach-Object { " * Database: $($_.name)" } | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
# $ag | Select-Object -Property * | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
"*/" | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
|
||
# Script the AG | ||
$ag.Script() | Out-File -FilePath $outfile -Encoding ASCII -Append | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Write-Output "No Availability Groups detected on $SqlServer" | ||
} | ||
} | ||
|
||
END | ||
{ | ||
$server.ConnectionContext.Disconnect() | ||
If ($Pscmdlet.ShouldProcess("console", "Showing finished message")) { Write-Output "Completed Export-DbaAvailabilityGroup on '$SqlServer'" } | ||
} | ||
If ($Pscmdlet.ShouldProcess("console", "Showing finished message")) { Write-Output "Completed Export-DbaAvailabilityGroup on $SqlServer" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,10 @@ Function Get-DbaMaxMemory | |
{ | ||
<# | ||
.SYNOPSIS | ||
Gets the 'Max Server Memory' configuration setting and the memory of the server. | ||
Works on SQL Server 2000-2014. | ||
Gets the 'Max Server Memory' configuration setting and the memory of the server. Works on SQL Server 2000-2014. | ||
.DESCRIPTION | ||
This cmdlet retrieves the SQL Server 'Max Server Memory' configuration setting as well as the total | ||
physical installed on the server. | ||
THIS CODE IS PROVIDED "AS IS", WITH NO WARRANTIES. | ||
This command retrieves the SQL Server 'Max Server Memory' configuration setting as well as the total physical installed on the server. | ||
.PARAMETER SqlServer | ||
Allows you to specify a comma separated list of servers to query. | ||
|
@@ -22,9 +18,6 @@ $cred = Get-Credential, then pass $cred variable to this parameter. | |
Windows Authentication will be used when SqlCredential is not specified. To connect as a different Windows user, run PowerShell as that user. | ||
.NOTES | ||
Author : Chrissy LeMaire (@cl), netnerds.net | ||
Requires: sysadmin access on SQL Servers | ||
dbatools PowerShell module (https://dbatools.io, [email protected]) | ||
Copyright (C) 2016 Chrissy LeMaire | ||
|
Oops, something went wrong.