From b865fa6da4868f9884d3c4784ef75cfac3c97bd4 Mon Sep 17 00:00:00 2001 From: Steffen Date: Thu, 18 Aug 2022 11:14:49 +0200 Subject: [PATCH 1/2] added default parameter set for connect --- CHANGELOG.md | 4 ++++ docs/Connect-SmoInstance.md | 22 +++++++++--------- src/PsSmo/ConnectInstanceCommand.cs | 35 +++++++++++++++++------------ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45d2251..f8c3ba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Default parameter set for `Connect-Instance`. + ## [1.0.0] - 2022-08-18 ### Added diff --git a/docs/Connect-SmoInstance.md b/docs/Connect-SmoInstance.md index d1a2f70..741ae6c 100644 --- a/docs/Connect-SmoInstance.md +++ b/docs/Connect-SmoInstance.md @@ -12,6 +12,12 @@ schema: 2.0.0 ## SYNTAX +### Properties_IntegratedSecurity (Default) +``` +Connect-SmoInstance [-DataSource] [[-InitialCatalog] ] [-AccessToken ] + [] +``` + ### SqlClient ``` Connect-SmoInstance -Connection [] @@ -22,13 +28,7 @@ Connect-SmoInstance -Connection [] Connect-SmoInstance [-ConnectionString] [] ``` -### Properties_IntegratedSecurity -``` -Connect-SmoInstance [-DataSource] [[-InitialCatalog] ] [-AccessToken ] - [] -``` - -### Properties_SQLServerAuthentication +### Properties_Credential ``` Connect-SmoInstance [-DataSource] [[-InitialCatalog] ] [-UserId] [-Password] [] @@ -98,7 +98,7 @@ Accept wildcard characters: False ```yaml Type: String -Parameter Sets: Properties_IntegratedSecurity, Properties_SQLServerAuthentication +Parameter Sets: Properties_IntegratedSecurity, Properties_Credential Aliases: Server, ServerName, ServerInstance Required: True @@ -113,7 +113,7 @@ Accept wildcard characters: False ```yaml Type: String -Parameter Sets: Properties_IntegratedSecurity, Properties_SQLServerAuthentication +Parameter Sets: Properties_IntegratedSecurity, Properties_Credential Aliases: Database, DatabaseName Required: False @@ -128,7 +128,7 @@ Accept wildcard characters: False ```yaml Type: SecureString -Parameter Sets: Properties_SQLServerAuthentication +Parameter Sets: Properties_Credential Aliases: Required: True @@ -143,7 +143,7 @@ Accept wildcard characters: False ```yaml Type: String -Parameter Sets: Properties_SQLServerAuthentication +Parameter Sets: Properties_Credential Aliases: Required: True diff --git a/src/PsSmo/ConnectInstanceCommand.cs b/src/PsSmo/ConnectInstanceCommand.cs index f2f2189..31fa0bf 100644 --- a/src/PsSmo/ConnectInstanceCommand.cs +++ b/src/PsSmo/ConnectInstanceCommand.cs @@ -8,10 +8,17 @@ namespace PsSmo { - [Cmdlet(VerbsCommunications.Connect, "Instance")] + [Cmdlet(VerbsCommunications.Connect, "Instance", DefaultParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED)] [OutputType(typeof(Server))] public class ConnectInstanceCommand : PSCmdlet { + #region ParameterSets + private const string PARAMETERSET_CONNECTION_STRING = "ConnectionString"; + private const string PARAMETERSET_PROPERTIES_INTEGRATED = "Properties_IntegratedSecurity"; + private const string PARAMETERSET_PROPERTIES_CREDENTIAL = "Properties_Credential"; + private const string PARAMETERSET_SQL_CLIENT = "SqlClient"; + #endregion + internal static Server Instance { get; set; } #region Parameters @@ -19,12 +26,12 @@ public class ConnectInstanceCommand : PSCmdlet [Parameter( Mandatory = true, ValueFromPipeline = true, - ParameterSetName = "SqlClient" + ParameterSetName = PARAMETERSET_SQL_CLIENT )] public SqlConnection Connection { get; set; } [Parameter( - ParameterSetName = "ConnectionString", + ParameterSetName = PARAMETERSET_CONNECTION_STRING, Position = 0, Mandatory = true, ValueFromPipeline = true, @@ -34,13 +41,13 @@ public class ConnectInstanceCommand : PSCmdlet public string ConnectionString { get; set; } [Parameter( - ParameterSetName = "Properties_IntegratedSecurity", + ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true )] [Parameter( - ParameterSetName = "Properties_SQLServerAuthentication", + ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true @@ -50,13 +57,13 @@ public class ConnectInstanceCommand : PSCmdlet public string DataSource { get; set; } [Parameter( - ParameterSetName = "Properties_IntegratedSecurity", + ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED, Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = true )] [Parameter( - ParameterSetName = "Properties_SQLServerAuthentication", + ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL, Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = true @@ -66,14 +73,14 @@ public class ConnectInstanceCommand : PSCmdlet public string InitialCatalog { get; set; } [Parameter( - ParameterSetName = "Properties_IntegratedSecurity", + ParameterSetName = PARAMETERSET_PROPERTIES_INTEGRATED, ValueFromPipelineByPropertyName = true )] [ValidateNotNullOrEmpty()] public string AccessToken { get; set; } [Parameter( - ParameterSetName = "Properties_SQLServerAuthentication", + ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL, Position = 1, Mandatory = true, ValueFromPipeline = true, @@ -82,7 +89,7 @@ public class ConnectInstanceCommand : PSCmdlet public string UserId { get; set; } [Parameter( - ParameterSetName = "Properties_SQLServerAuthentication", + ParameterSetName = PARAMETERSET_PROPERTIES_CREDENTIAL, Position = 1, Mandatory = true, ValueFromPipeline = true, @@ -98,7 +105,7 @@ protected override void ProcessRecord() switch (ParameterSetName) { - case "SqlClient": + case PARAMETERSET_SQL_CLIENT: WriteVerbose("Connect by existing connection"); Instance = new Server( serverConnection: new ServerConnection( @@ -107,7 +114,7 @@ protected override void ProcessRecord() ); break; - case "ConnectionString": + case PARAMETERSET_CONNECTION_STRING: { WriteVerbose("Connect by connection string"); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); @@ -121,7 +128,7 @@ protected override void ProcessRecord() break; } - case "Properties_IntegratedSecurity": + case PARAMETERSET_PROPERTIES_INTEGRATED: { WriteVerbose("Connect by Integrated Security"); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); @@ -148,7 +155,7 @@ protected override void ProcessRecord() break; } - case "Properties_SQLServerAuthentication": + case PARAMETERSET_PROPERTIES_CREDENTIAL: { WriteVerbose("Connect by SQL Server Authentication"); SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); From 1e3fadfd76e00830f4d7942057e7af5ceb383fb0 Mon Sep 17 00:00:00 2001 From: Steffen Date: Thu, 18 Aug 2022 11:17:09 +0200 Subject: [PATCH 2/2] changed version --- CHANGELOG.md | 2 ++ src/PsSmo/PsSmo.psd1 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c3ba2..c3c6448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.0] - 2022-08-18 + ### Added - Default parameter set for `Connect-Instance`. diff --git a/src/PsSmo/PsSmo.psd1 b/src/PsSmo/PsSmo.psd1 index 543507f..23e1132 100644 --- a/src/PsSmo/PsSmo.psd1 +++ b/src/PsSmo/PsSmo.psd1 @@ -12,7 +12,7 @@ RootModule = 'PsSmo.dll' # Version number of this module. -ModuleVersion = '1.0.0' +ModuleVersion = '1.1.0' # Supported PSEditions # CompatiblePSEditions = @()