Skip to content

Commit

Permalink
ConnectServer cmdlet - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Oct 10, 2023
1 parent c003a08 commit dd0d66c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
[Ll]og/
[Ll]ogs/

[Oo]utput/
[Oo]utput/
.DS_Store
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $dll = Get-ChildItem -Recurse -File -Filter $dllFileName | Select-Object -First
if ($dll) {
Write-Host "dotnet build successful, found $($dll.FullName)"
Write-Host " - Build $($Module.Name) $SemVer" -ForegroundColor Cyan
Build-Module -SourcePath ./source -Target CleanBuild -OutputDirectory $OutputDirectory
Build-Module -SourcePath ./source -Target CleanBuild -OutputDirectory $OutputDirectory -Verbose
} else {
Write-Warning "Module-Builder could not run, unable to find DLL library: $dllFileName"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

namespace dbalight.commands
namespace dbalight.cmdlets.general
{
/// <summary>
/// <para type="synopsis"></para>
/// <para type="description"></para>
/// </summary>
[Cmdlet(VerbsCommunications.Connect, "Server")]
public class ConnectServerCmdlet : PSCmdlet
public class ConnectServerCmdlet : Cmdlet
{
/// <summary>
/// <para type="description">The name of the SQL Server the command will connect to.</para>
Expand All @@ -30,19 +30,34 @@ public PSCredential Credential
}
private PSCredential sqlCredential;

protected override void BeginProcessing()
{
WriteVerbose("Creating connection to ServerInstance: " + serverInstance);
}

protected override void ProcessRecord()
{
// Build Server connection details
ServerConnection srvCn = new ServerConnection();
if (MyInvocation.BoundParameters.ContainsKey("Credential"))

// Check if Credential parameter was specified
if (Credential != null)
{
// do something
// If Credential parameter was specified, use it to connect to the SQL Server instance
srvCn.LoginSecure = false;
srvCn.Login = Credential.UserName;
srvCn.SecurePassword = Credential.Password;
}
else
{
WriteVerbose("Credential was not provided, defaulting to Windows Authentication");
// If Credential parameter was not specified, use Windows Authentication to connect to the SQL Server instance
srvCn.LoginSecure = true;
}
// Connect to the SQL Server instance specified by the Path parameter
Server srv = new Server(srvCn);

// Write the value of the specified property to the output
WriteObject(srv);
WriteVerbose("Server object created");
WriteObject(srv, true);
}
}
}
2 changes: 1 addition & 1 deletion source/dbalight/dbalight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Library</OutputType>
<RootNamespace>dbalight</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>osx.12-arm64</RuntimeIdentifier>
<!-- <RuntimeIdentifier>osx.12-arm64</RuntimeIdentifier> -->
<AssemblyName>dbalight</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down

0 comments on commit dd0d66c

Please sign in to comment.