Skip to content

Commit

Permalink
Merge pull request #428 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
v0.8.691
  • Loading branch information
Chrissy LeMaire authored Dec 14, 2016
2 parents e17e074 + cb61266 commit 1b1b776
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 453 deletions.
2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.8.69'
ModuleVersion = '0.8.691'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
256 changes: 127 additions & 129 deletions functions/Export-DbaAvailabiltyGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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" }
}
}
6 changes: 3 additions & 3 deletions functions/Get-DbaDatabaseSnapshot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ You should have received a copy of the GNU General Public License along with thi
.EXAMPLE
Get-DbaDatabaseSnapshot -SqlServer sqlserver2014a
Returns a custom object displaying Server, Database, DatabaseCreated, SnapshotOf
Returns a custom object displaying Server, Database, DatabaseCreated, SnapshotOf, SizeMB, DatabaseCreated, IsReadCommittedSnapshotOn, SnapshotIsolationState
.EXAMPLE
Get-DbaDatabaseSnapshot -SqlServer sqlserver2014a -Databases HR, Accounting
Returns informations for database snapshots having HR and Accounting as base dbs
Returns information for database snapshots having HR and Accounting as base dbs
.EXAMPLE
Get-DbaDatabaseSnapshot -SqlServer sqlserver2014a -Snapshots HR_snapshot, Accounting_snapshot
Returns informations for database snapshots HR_snapshot and Accounting_snapshot
Returns information for database snapshots HR_snapshot and Accounting_snapshot
#>
[CmdletBinding()]
Expand Down
11 changes: 2 additions & 9 deletions functions/Get-DbaMaxMemory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Loading

0 comments on commit 1b1b776

Please sign in to comment.