Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.71 KB

README.md

File metadata and controls

54 lines (42 loc) · 1.71 KB

NetOnlyImpersonation PowerShell module

A PowerShell module that allows using windows integrated authentication through identity impersonation to access protected resources on remote systems as a different user without any trust.

Example - Azure automation runbook

Connecting from Azure automation runbook to SQLSever VM using windows integrated security

workflow Main-Workflow
{
    InlineScript
    {
        Import-Module -Name NetOnlyImpersonation

        $credential = Get-AutomationPSCredential -Name 'my-automation-credential';

        $context = New-Object NetOnlyImpersonation.NetOnlyImpersonationContext(".", $credential.UserName, $credential.GetNetworkCredential().Password);
        try
        {
            $connection = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:sqlserver-vm.cloudapp.net,1433;Integrated Security=True;");
            try
            {
                $connection.Open();

                $command = New-Object System.Data.SqlClient.SqlCommand("SELECT ORIGINAL_LOGIN();", $connection);  
                $message = $command.ExecuteScalar();
                $message
            }
            finally
            {
                $connection.Dispose();        
            }
        }
        finally
        {
            $context.Dispose();
        }
    }
}

$ErrorActionPreference = "Stop"
Write-Output "Start"
Main-Workflow
Write-Output "Stop"

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details