Skip to content

Commit 82df624

Browse files
committed
Add ShouldProcess and Force
1 parent 999f9bb commit 82df624

File tree

7 files changed

+215
-30
lines changed

7 files changed

+215
-30
lines changed

src/Sql/Sql/Database/Cmdlet/InvokeAzureSqlDatabaseFailover.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace Microsoft.Azure.Commands.Sql.Database.Cmdlet
2222
{
23-
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlDatabaseFailover"), OutputType(typeof(bool))]
23+
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlDatabaseFailover", SupportsShouldProcess = true), OutputType(typeof(bool))]
2424
public class InvokeAzureSqlDatabaseFailover : AzureSqlDatabaseCmdletBase<IEnumerable<AzureSqlDatabaseModel>>
2525
{
2626
/// <summary>
@@ -41,9 +41,18 @@ public class InvokeAzureSqlDatabaseFailover : AzureSqlDatabaseCmdletBase<IEnumer
4141
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
4242
public SwitchParameter AsJob { get; set; }
4343

44+
/// <summary>
45+
/// Defines whether the cmdlets will output a boolean at the end of its execution
46+
/// </summary>
4447
[Parameter(Mandatory = false)]
4548
public SwitchParameter PassThru { get; set; }
4649

50+
/// <summary>
51+
/// Defines whether it is ok to skip the requesting of failover database confirmation
52+
/// </summary>
53+
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
54+
public SwitchParameter Force { get; set; }
55+
4756
/// <summary>
4857
/// Get the entities from the service
4958
/// </summary>
@@ -76,8 +85,19 @@ protected override IEnumerable<AzureSqlDatabaseModel> PersistChanges(IEnumerable
7685
return entity;
7786
}
7887

88+
/// <summary>
89+
/// Entry point for the cmdlet
90+
/// </summary>
7991
public override void ExecuteCmdlet()
8092
{
93+
if (!Force.IsPresent && !ShouldProcess(
94+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.FailoverAzureSqlDatabaseDescription, this.DatabaseName, this.ServerName),
95+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.FailoverAzureSqlDatabaseWarning, this.DatabaseName, this.ServerName),
96+
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption))
97+
{
98+
return;
99+
}
100+
81101
base.ExecuteCmdlet();
82102

83103
if (this.PassThru.IsPresent)

src/Sql/Sql/Elastic Pools/Cmdlet/InvokeAzureSqlElasticPoolFailover.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet
2222
{
23-
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlElasticPoolFailover"), OutputType(typeof(bool))]
23+
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlElasticPoolFailover", SupportsShouldProcess = true), OutputType(typeof(bool))]
2424
public class InvokeAzureSqlElasticPoolFailover : AzureSqlElasticPoolCmdletBase
2525
{
2626
/// <summary>
@@ -41,9 +41,18 @@ public class InvokeAzureSqlElasticPoolFailover : AzureSqlElasticPoolCmdletBase
4141
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
4242
public SwitchParameter AsJob { get; set; }
4343

44+
/// <summary>
45+
/// Defines whether the cmdlets will output a boolean at the end of its execution
46+
/// </summary>
4447
[Parameter(Mandatory = false)]
4548
public SwitchParameter PassThru { get; set; }
4649

50+
/// <summary>
51+
/// Defines whether it is ok to skip the requesting of failover pool confirmation
52+
/// </summary>
53+
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
54+
public SwitchParameter Force { get; set; }
55+
4756
/// <summary>
4857
/// Get the entities from the service
4958
/// </summary>
@@ -76,8 +85,19 @@ protected override IEnumerable<AzureSqlElasticPoolModel> PersistChanges(IEnumera
7685
return entity;
7786
}
7887

88+
/// <summary>
89+
/// Entry point for the cmdlet
90+
/// </summary>
7991
public override void ExecuteCmdlet()
8092
{
93+
if (!Force.IsPresent && !ShouldProcess(
94+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.FailoverAzureSqlElasticPoolDescription, this.ElasticPoolName, this.ServerName),
95+
string.Format(CultureInfo.InvariantCulture, Microsoft.Azure.Commands.Sql.Properties.Resources.FailoverAzureSqlElasticPoolWarning, this.ElasticPoolName, this.ServerName),
96+
Microsoft.Azure.Commands.Sql.Properties.Resources.ShouldProcessCaption))
97+
{
98+
return;
99+
}
100+
81101
base.ExecuteCmdlet();
82102

83103
if (this.PassThru.IsPresent)

src/Sql/Sql/Properties/Resources.Designer.cs

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sql/Sql/Properties/Resources.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,16 @@
483483
<value>Are you sure you want to remove the Azure SQL Instance pool '{0}'?</value>
484484
<comment>Instance pools</comment>
485485
</data>
486+
<data name="FailoverAzureSqlDatabaseDescription" xml:space="preserve">
487+
<value>Failing over Azure Sql Database '{0}' on server '{1}'.</value>
488+
</data>
489+
<data name="FailoverAzureSqlDatabaseWarning" xml:space="preserve">
490+
<value>Are you sure you want to failover the Azure Sql Database '{0}' on server '{1}'?</value>
491+
</data>
492+
<data name="FailoverAzureSqlElasticPoolDescription" xml:space="preserve">
493+
<value>Failing over Azure Sql Elastic Pool '{0}' on server '{1}'.</value>
494+
</data>
495+
<data name="FailoverAzureSqlElasticPoolWarning" xml:space="preserve">
496+
<value>Are you sure you want to failover the Azure Sql Elastic Pool '{0}' on server '{1}'?</value>
497+
</data>
486498
</root>

src/Sql/Sql/help/Az.Sql.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ Gets the advanced threat protection settings for a database.
8989
### [Get-AzSqlDatabaseAdvisor](Get-AzSqlDatabaseAdvisor.md)
9090
Gets one or more Advisors for an Azure SQL Database.
9191

92-
### [Get-AzSqlDatabaseAuditing](Get-AzSqlDatabaseAuditing.md)
92+
### [Get-AzSqlDatabaseAudit](Get-AzSqlDatabaseAudit.md)
9393
Gets the auditing settings of an Azure SQL database.
9494

95-
### [Get-AzSqlDatabaseAudit](Get-AzSqlDatabaseAudit.md)
95+
### [Get-AzSqlDatabaseAuditing](Get-AzSqlDatabaseAuditing.md)
9696
Gets the auditing settings of an Azure SQL database.
9797

9898
### [Get-AzSqlDatabaseBackupLongTermRetentionPolicy](Get-AzSqlDatabaseBackupLongTermRetentionPolicy.md)
@@ -119,15 +119,15 @@ Gets a geo-redundant backup of a database.
119119
### [Get-AzSqlDatabaseGeoBackupPolicy](Get-AzSqlDatabaseGeoBackupPolicy.md)
120120
Gets a database geo backup policy.
121121

122-
### [Get-AzSqlDatabaseInstanceFailoverGroup](Get-AzSqlDatabaseInstanceFailoverGroup.md)
123-
Gets or lists Azure SQL Database Instance Failover Groups.
124-
125122
### [Get-AzSqlDatabaseImportExportStatus](Get-AzSqlDatabaseImportExportStatus.md)
126123
Gets the details of an import or export of an Azure SQL Database.
127124

128125
### [Get-AzSqlDatabaseIndexRecommendation](Get-AzSqlDatabaseIndexRecommendation.md)
129126
Gets the recommended index operations for a server or database.
130127

128+
### [Get-AzSqlDatabaseInstanceFailoverGroup](Get-AzSqlDatabaseInstanceFailoverGroup.md)
129+
Gets or lists Instance Failover Groups.
130+
131131
### [Get-AzSqlDatabaseLongTermRetentionBackup](Get-AzSqlDatabaseLongTermRetentionBackup.md)
132132
Gets one or more long term retention backups.
133133

@@ -255,10 +255,10 @@ Gets the advanced threat protection settings for a server.
255255
### [Get-AzSqlServerAdvisor](Get-AzSqlServerAdvisor.md)
256256
Gets one or more Advisors for an Azure SQL Server.
257257

258-
### [Get-AzSqlServerAuditing](Get-AzSqlServerAuditing.md)
258+
### [Get-AzSqlServerAudit](Get-AzSqlServerAudit.md)
259259
Gets the auditing settings of an Azure SQL server.
260260

261-
### [Get-AzSqlServerAudit](Get-AzSqlServerAudit.md)
261+
### [Get-AzSqlServerAuditing](Get-AzSqlServerAuditing.md)
262262
Gets the auditing settings of an Azure SQL server.
263263

264264
### [Get-AzSqlServerCommunicationLink](Get-AzSqlServerCommunicationLink.md)
@@ -318,6 +318,12 @@ Returns information about the sync schema of a member database or a hub database
318318
### [Get-AzSqlVirtualCluster](Get-AzSqlVirtualCluster.md)
319319
Returns information about Azure SQL Virtual Cluster.
320320

321+
### [Invoke-AzSqlDatabaseFailover](Invoke-AzSqlDatabaseFailover.md)
322+
Failovers a database.
323+
324+
### [Invoke-AzSqlElasticPoolFailover](Invoke-AzSqlElasticPoolFailover.md)
325+
Failovers an elastic pool.
326+
321327
### [New-AzSqlDatabase](New-AzSqlDatabase.md)
322328
Creates a database or an elastic database.
323329

@@ -333,12 +339,12 @@ Exports an Azure SQL Database as a .bacpac file to a storage account.
333339
### [New-AzSqlDatabaseFailoverGroup](New-AzSqlDatabaseFailoverGroup.md)
334340
This command creates a new Azure SQL Database Failover Group.
335341

336-
### [New-AzSqlDatabaseInstanceFailoverGroup](New-AzSqlDatabaseInstanceFailoverGroup.md)
337-
This command creates a new Azure SQL Database Instance Failover Group.
338-
339342
### [New-AzSqlDatabaseImport](New-AzSqlDatabaseImport.md)
340343
Imports a .bacpac file and create a new database on the server.
341344

345+
### [New-AzSqlDatabaseInstanceFailoverGroup](New-AzSqlDatabaseInstanceFailoverGroup.md)
346+
This command creates a new Azure SQL Database Instance Failover Group.
347+
342348
### [New-AzSqlDatabaseRestorePoint](New-AzSqlDatabaseRestorePoint.md)
343349
Creates a new restore point from which a SQL Database can be restored.
344350

@@ -391,20 +397,20 @@ Creates an Azure SQL Database Sync Member.
391397
Removes an Azure SQL database.
392398

393399
### [Remove-AzSqlDatabaseAudit](Remove-AzSqlDatabaseAudit.md)
394-
Removes the audit policy of a SQL Database.
400+
Removes the auditing settings of an Azure SQL database.
395401

396402
### [Remove-AzSqlDatabaseDataMaskingRule](Remove-AzSqlDatabaseDataMaskingRule.md)
397403
Removes a data masking rule from a database.
398404

399405
### [Remove-AzSqlDatabaseFailoverGroup](Remove-AzSqlDatabaseFailoverGroup.md)
400406
Removes an Azure SQL Database Failover Group.
401407

402-
### [Remove-AzSqlDatabaseInstanceFailoverGroup](Remove-AzSqlDatabaseInstanceFailoverGroup.md)
403-
Removes an Azure SQL Database Instance Failover Group.
404-
405408
### [Remove-AzSqlDatabaseFromFailoverGroup](Remove-AzSqlDatabaseFromFailoverGroup.md)
406409
Removes one or more databases from an Azure SQL Database Failover Group.
407410

411+
### [Remove-AzSqlDatabaseInstanceFailoverGroup](Remove-AzSqlDatabaseInstanceFailoverGroup.md)
412+
Removes an Instance Failover Group.
413+
408414
### [Remove-AzSqlDatabaseLongTermRetentionBackup](Remove-AzSqlDatabaseLongTermRetentionBackup.md)
409415
Deletes a long term retention backup.
410416

@@ -442,7 +448,7 @@ Removes an Azure SQL Database server.
442448
Removes an Azure AD administrator for SQL Server.
443449

444450
### [Remove-AzSqlServerAudit](Remove-AzSqlServerAudit.md)
445-
Removes the audit policy of a SQL Server.
451+
Removes the auditing settings of an Azure SQL server.
446452

447453
### [Remove-AzSqlServerCommunicationLink](Remove-AzSqlServerCommunicationLink.md)
448454
Deletes a communication link for elastic database transactions between two servers.
@@ -489,10 +495,10 @@ Sets properties for a database, or moves an existing database into an elastic po
489495
### [Set-AzSqlDatabaseAdvisorAutoExecuteStatus](Set-AzSqlDatabaseAdvisorAutoExecuteStatus.md)
490496
Modifies auto execute status of an Azure SQL Database Advisor.
491497

492-
### [Set-AzSqlDatabaseAuditing](Set-AzSqlDatabaseAuditing.md)
498+
### [Set-AzSqlDatabaseAudit](Set-AzSqlDatabaseAudit.md)
493499
Changes the auditing settings for an Azure SQL database.
494500

495-
### [Set-AzSqlDatabaseAudit](Set-AzSqlDatabaseAudit.md)
501+
### [Set-AzSqlDatabaseAuditing](Set-AzSqlDatabaseAuditing.md)
496502
Changes the auditing settings for an Azure SQL database.
497503

498504
### [Set-AzSqlDatabaseBackupLongTermRetentionPolicy](Set-AzSqlDatabaseBackupLongTermRetentionPolicy.md)
@@ -510,12 +516,12 @@ Sets the properties of a data masking rule for a database.
510516
### [Set-AzSqlDatabaseFailoverGroup](Set-AzSqlDatabaseFailoverGroup.md)
511517
Modifies the configuration of an Azure SQL Database Failover Group.
512518

513-
### [Set-AzSqlDatabaseInstanceFailoverGroup](Set-AzSqlDatabaseInstanceFailoverGroup.md)
514-
Modifies the configuration of an Azure SQL Database Instance Failover Group.
515-
516519
### [Set-AzSqlDatabaseGeoBackupPolicy](Set-AzSqlDatabaseGeoBackupPolicy.md)
517520
Sets a database geo backup policy.
518521

522+
### [Set-AzSqlDatabaseInstanceFailoverGroup](Set-AzSqlDatabaseInstanceFailoverGroup.md)
523+
Modifies the configuration of an Instance Failover Group.
524+
519525
### [Set-AzSqlDatabaseRecommendedActionState](Set-AzSqlDatabaseRecommendedActionState.md)
520526
Updates the state of an Azure SQL Database recommended action.
521527

@@ -567,10 +573,10 @@ Provisions an Azure AD administrator for SQL Server.
567573
### [Set-AzSqlServerAdvisorAutoExecuteStatus](Set-AzSqlServerAdvisorAutoExecuteStatus.md)
568574
Updates the auto execute status of an Azure SQL Server Advisor.
569575

570-
### [Set-AzSqlServerAuditing](Set-AzSqlServerAuditing.md)
576+
### [Set-AzSqlServerAudit](Set-AzSqlServerAudit.md)
571577
Changes the auditing settings of an Azure SQL server.
572578

573-
### [Set-AzSqlServerAudit](Set-AzSqlServerAudit.md)
579+
### [Set-AzSqlServerAuditing](Set-AzSqlServerAuditing.md)
574580
Changes the auditing settings of an Azure SQL server.
575581

576582
### [Set-AzSqlServerDisasterRecoveryConfiguration](Set-AzSqlServerDisasterRecoveryConfiguration.md)
@@ -622,7 +628,7 @@ Suspends a SQL Data Warehouse database.
622628
Executes a failover of an Azure SQL Database Failover Group.
623629

624630
### [Switch-AzSqlDatabaseInstanceFailoverGroup](Switch-AzSqlDatabaseInstanceFailoverGroup.md)
625-
Executes a failover of an Azure SQL Database Instance Failover Group.
631+
Executes a failover of an Instance Failover Group.
626632

627633
### [Update-AzSqlDatabaseAdvancedThreatProtectionSettings](Update-AzSqlDatabaseAdvancedThreatProtectionSettings.md)
628634
Sets a advanced threat protection settings on a database.

src/Sql/Sql/help/Invoke-AzSqlDatabaseFailover.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Failovers a database.
1313
## SYNTAX
1414

1515
```
16-
Invoke-AzSqlDatabaseFailover [-DatabaseName] <String> [-AsJob] [-PassThru] [-ServerName] <String>
17-
[-ResourceGroupName] <String> [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
16+
Invoke-AzSqlDatabaseFailover [-DatabaseName] <String> [-AsJob] [-PassThru] [-Force] [-ServerName] <String>
17+
[-ResourceGroupName] <String> [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
18+
[<CommonParameters>]
1819
```
1920

2021
## DESCRIPTION
@@ -76,6 +77,21 @@ Accept pipeline input: False
7677
Accept wildcard characters: False
7778
```
7879
80+
### -Force
81+
Skip confirmation message for performing the action
82+
83+
```yaml
84+
Type: System.Management.Automation.SwitchParameter
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: False
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
7995
### -PassThru
8096
On Successful execution, returns true. By default, this cmdlet does not generate any output.
8197
@@ -121,6 +137,36 @@ Accept pipeline input: True (ByPropertyName)
121137
Accept wildcard characters: False
122138
```
123139
140+
### -Confirm
141+
Prompts you for confirmation before running the cmdlet.
142+
143+
```yaml
144+
Type: System.Management.Automation.SwitchParameter
145+
Parameter Sets: (All)
146+
Aliases: cf
147+
148+
Required: False
149+
Position: Named
150+
Default value: None
151+
Accept pipeline input: False
152+
Accept wildcard characters: False
153+
```
154+
155+
### -WhatIf
156+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
157+
158+
```yaml
159+
Type: System.Management.Automation.SwitchParameter
160+
Parameter Sets: (All)
161+
Aliases: wi
162+
163+
Required: False
164+
Position: Named
165+
Default value: None
166+
Accept pipeline input: False
167+
Accept wildcard characters: False
168+
```
169+
124170
### CommonParameters
125171
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
126172
@@ -134,7 +180,6 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
134180
135181
## RELATED LINKS
136182
137-
138183
[Get-AzSqlDatabase](./Get-AzSqlDatabase.md)
139184
140185
[Invoke-AzSqlElasticPoolFailover](./Invoke-AzSqlElasticPoolFailover.md)

0 commit comments

Comments
 (0)