PowerShell remoting ไปยังเซิร์ฟเวอร์ที่ใช้ CNAME ไม่ใช่ชื่อคอมพิวเตอร์


9

ฉันพยายามที่จะให้ powerhell remoting ทำงานกับเซิร์ฟเวอร์โดยใช้ชื่อ CNAME แทนที่จะเป็นชื่อคอมพิวเตอร์ ทั้งเครื่องโลคัลและรีโมตอยู่บนเครือข่ายและโดเมนเดียวกัน

ฉันเปิดใช้งานรีโมท powerhell และทำงานได้ดีกับชื่อคอมพิวเตอร์ ฉันได้ตั้งค่า TrustedHost ของฉันเป็น CNAME และได้เพิ่ม SPN สำหรับ CNAME อย่างไรก็ตามเมื่อฉันออกEnter-PSSession CNAMEฉันได้รับต่อไปนี้:

Enter-PSSession : Connecting to remote server CNAME failed with the following
error message : WinRM cannot process the request. The following error
occurred while using Kerberos authentication: Cannot find the computer CNAME.
Verify that the computer exists on the network and that the name
provided is spelled correctly. For more information, see the
about_Remote_Troubleshooting Help topic.

การดำเนินการsetspn -l COMPUTERNAMEให้ฉันนี้:

Registered ServicePrincipalNames for CN=COMPUTERNAME,OU=SERVERS,DC=COMPANY,DC=private:
        WSMAN/CNAME
        WSMAN/COMPUTERNAME
        WSMAN/COMPUTERNAME.local
        TERMSRV/COMPUTERNAME
        TERMSRV/COMPUTERNAME.local
        HOST/COMPUTERNAME
        HOST/COMPUTERNAME.local

ต้องใช้อะไรอีกเพื่อเปิดใช้การเข้าถึงผ่าน CNAME

คำตอบ:


5

สิ่งที่ฉันทำเพื่อแก้ไขปัญหานี้คือการสร้างฟังก์ชันพร็อกซีสำหรับ Enter-PSSession ที่แก้ไข CNAME ให้ฉัน สิ่งนี้อาจไม่ได้ผลในกรณีของคุณขึ้นอยู่กับสาเหตุที่คุณต้องใช้ CNAME แต่มันใช้งานได้สำหรับฉัน

รายละเอียดเกี่ยวกับฟังก์ชั่น proxy powershell: http://www.windowsitpro.com/blog/powershell-with-a-purpose-blog-36/windows-powershell/powershell-proxy-functions-141413

ฟังก์ชั่นเต็มรูปแบบ:

function Enter-PSSession {
[CmdletBinding(DefaultParameterSetName='ComputerName')]
param(
    [Parameter(ParameterSetName='ComputerName', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
    [Alias('Cn')]
    [ValidateNotNullOrEmpty()]
    [string]
    ${ComputerName},

[Parameter(ParameterSetName='Session', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.Runspaces.PSSession]
${Session},

[Parameter(ParameterSetName='Uri', Position=1, ValueFromPipelineByPropertyName=$true)]
[Alias('URI','CU')]
[ValidateNotNullOrEmpty()]
[uri]
${ConnectionUri},

[Parameter(ParameterSetName='InstanceId', ValueFromPipelineByPropertyName=$true)]
[ValidateNotNull()]
[guid]
${InstanceId},

[Parameter(ParameterSetName='Id', Position=0, ValueFromPipelineByPropertyName=$true)]
[ValidateNotNull()]
[int]
${Id},

[Parameter(ParameterSetName='Name', ValueFromPipelineByPropertyName=$true)]
[string]
${Name},

[Parameter(ParameterSetName='Uri')]
[Parameter(ParameterSetName='ComputerName')]
[switch]
${EnableNetworkAccess},

[Parameter(ParameterSetName='ComputerName', ValueFromPipelineByPropertyName=$true)]
[Parameter(ParameterSetName='Uri', ValueFromPipelineByPropertyName=$true)]
[system.management.automation.pscredential]
${Credential},

[Parameter(ParameterSetName='ComputerName')]
[ValidateRange(1, 65535)]
[int]
${Port},

[Parameter(ParameterSetName='ComputerName')]
[switch]
${UseSSL},

[Parameter(ParameterSetName='ComputerName', ValueFromPipelineByPropertyName=$true)]
[Parameter(ParameterSetName='Uri', ValueFromPipelineByPropertyName=$true)]
[string]
${ConfigurationName},

[Parameter(ParameterSetName='ComputerName', ValueFromPipelineByPropertyName=$true)]
[string]
${ApplicationName},

[Parameter(ParameterSetName='Uri')]
[switch]
${AllowRedirection},

[Parameter(ParameterSetName='Uri')]
[Parameter(ParameterSetName='ComputerName')]
[ValidateNotNull()]
[System.Management.Automation.Remoting.PSSessionOption]
${SessionOption},

[Parameter(ParameterSetName='Uri')]
[Parameter(ParameterSetName='ComputerName')]
[System.Management.Automation.Runspaces.AuthenticationMechanism]
${Authentication},

[Parameter(ParameterSetName='Uri')]
[Parameter(ParameterSetName='ComputerName')]
[string]
${CertificateThumbprint})


begin
{
    try {
        $outBuffer = $null
        if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
        {
            $PSBoundParameters['OutBuffer'] = 1
        }
        $PSBoundParameters['ComputerName'] = ([System.Net.Dns]::GetHostByName($PSBoundParameters['ComputerName'])).HostName
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Core\Enter-PSSession', [System.Management.Automation.CommandTypes]::Cmdlet)
        $scriptCmd = {& $wrappedCmd @PSBoundParameters }
        $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
        $steppablePipeline.Begin($PSCmdlet)
    } catch {
        throw
    }
}

process
{
    try {
        $steppablePipeline.Process($_)
    } catch {
        throw
    }
}

end
{
    try {
        $steppablePipeline.End()
    } catch {
        throw
    }
}
<#

.ForwardHelpTargetName Enter-PSSession
.ForwardHelpCategory Cmdlet

#>

}

บรรทัดเดียวที่ฉันเพิ่มคือ:

$PSBoundParameters['ComputerName'] = ([System.Net.Dns]::GetHostByName($PSBoundParameters['ComputerName'])).HostName

สิ่งนี้จะแก้ไข CNAME เป็น FQDN ในฟังก์ชันพร็อกซีก่อนที่จะเรียกใช้ Enter-PSSession ดั้งเดิม

สิ่งนี้ทำให้ฉันสามารถตั้งค่า * .mydomain.local ใน TrustedHosts ของฉันผ่านนโยบายกลุ่มและฉันยังสามารถใช้ "Enter-PSSession ShortName" หรือ "Enter-PSSession CNAME" ได้โดยไม่ต้องยุ่งกับ SPNs เพิ่มเติม ฯลฯ


ใช้งานได้ดี ขอบคุณ.
majkinetor
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.