チュートリアル: Always On VPN を展開する - Windows 10 以降のクライアン用の Always On VPN プロファイルを構成する

適用対象: Windows Server 2022、Windows Server 2019、Windows Server 2016、Windows Server 2012 R2、Windows 10、Windows 11

このチュートリアルの最後の部分では、ProfileXML PowerShell 構成スクリプトを使用して、Always On VPN 設定を構成し、クライアント接続用のユーザー トンネルを作成する方法について説明します。

構成サービス プロバイダー (CSP) の Always on VPN 構成オプションの詳細については、VPNv2 構成サービス プロバイダーに関するページを参照してください。

前提条件

チュートリアル: Always On VPN の展開 - 証明機関テンプレートを構成する」を完了します。

Always On VPN クライアント プロファイルを作成する

このセクションでは、VPN テスト クライアントが正常な VPN 接続を確立できることを確認するために、VPN クライアント接続を作成します。 これにより、次のセクションでエクスポートするための EAP 設定を作成することもできます。

EAP 設定の詳細については、「EAP の構成」を参照してください。

  1. Active Directory テスト ユーザーの作成に関するセクションで作成した VPN ユーザーとして、ドメインに参加している VPN クライアント コンピューターにサインインします。

  2. [スタート] メニューで、「VPN」と入力して [VPN の設定] を選択します。 ENTER キーを押します。

  3. 詳細ペインで、[VPN 接続を追加する] をクリックします。

  4. [VPN プロバイダー] で、[Windows (ビルトイン)] を選択します。

  5. [接続名] に「Contoso VPN」と入力します。

  6. [サーバー名またはアドレス] に、VPN サーバーの外部 FQDN (たとえば vpn.contoso.com) を入力します。

  7. [VPN の種類][IKEv2] を選択します。

  8. [サインイン情報の種類] [証明書] を選択します。

  9. [保存] を選択します。

  10. [関連設定] で、[アダプターのオプションを変更する] を選択します。

  11. Contoso VPN を右クリックし、プロパティ を選択します。

  12. [セキュリティ] タブの [データの暗号化] で、[最強の暗号化] を選択します。

  13. [Use Extensible Authentication Protocol (EAP)] (拡張認証プロトコルを使う (EAP)) を選択します。 次に、[Use Extensible Authentication Protocol (EAP)] (拡張認証プロトコルを使う (EAP)) で、[Microsoft: Protected EAP (PEAP) (encryption enabled)] (Microsoft:保護された EAP (PEAP) (暗号化が有効)) を選択します。

  14. [プロパティ] を選択して [保護された EAP のプロパティ] を開き、次の手順を実行します。

    1. [次のサーバーに接続する] に NPS サーバーの名前を入力します。

    2. [信頼されたルート証明機関] で、NPS サーバーの証明書を発行したルート CA (たとえば contoso-CA) を選択します。

    3. [接続前の通知] で、[新しいサーバーまたは信頼された CA を承認するときにユーザーに確認を求めません] を選択します。

    4. [認証方法を選択する] で、[スマート カードまたはその他の証明書] を選択します。

    5. [構成] をクリックします。

      1. [このコンピューターの証明書を使う] を選択します。

      2. [次のサーバーに接続する] に NPS サーバーの名前を入力します。

      3. [信頼されたルート証明機関] で、NPS サーバーの証明書を発行したルート CA を選択します。

      4. [新しいサーバーまたは信頼された証明機関を承認するようユーザーに求めない] をオンにします。

      5. [OK] を選択して [スマート カードまたはその他の証明書のプロパティ] を閉じます。

      6. [OK] を選択して、[保護された EAP のプロパティ] を閉じます。

    6. [OK] を選択して、[Contoso VPN のプロパティ] を閉じます。

  15. [ネットワーク接続] ウィンドウを閉じます。

  16. [設定] で [Contoso VPN] を選択し、[接続] を選択します。

重要

VPN サーバーへのテンプレート VPN 接続が正常に行われていることを確認します。 こうすることにより、次の手順で使用する前に、EAP 設定が正しいことを確認できます。 続行する前に、少なくとも 1 回接続する必要があります。そうしないと、VPN に接続するために必要なすべての情報がプロファイルに取り込まれません。

Windows VPN クライアントを構成する

このセクションでは、PowerShell スクリプトを使用して Windows VPN クライアントを手動で構成します。

  1. VPN ユーザーとして VPN クライアント コンピューターにサインインします。

  2. 管理者として Windows PowerShell Integrated Scripting Environment (ISE) を開きます。

  3. 次のスクリプトをコピーして貼り付けます。

    
    # Define key VPN profile parameters
    # Replace with your own values
    
    $Domain = 'corp' # Name of the domain.
    
    $TemplateName = 'Contoso VPN' # Name of the test VPN connection you created in the tutorial. 
    
    $ProfileName = 'Contoso AlwaysOn VPN' # Name of the profile we are going to create.
    
    $Servers = 'aov-vpn.contoso.com' #Public or routable IP address or DNS name for the VPN gateway.
    
    $DnsSuffix = 'corp.contoso.com' # Specifies one or more commas separated DNS suffixes. 
    
    $DomainName = '.corp.contoso.com' #Used to indicate the namespace to which the policy applies. Contains `.` prefix.
    
    $DNSServers = '10.10.0.6' #List of comma-separated DNS Server IP addresses to use for the namespace.
    
    $TrustedNetwork = 'corp.contoso.com' #Comma-separated string to identify the trusted network.
    
    
    #Get the EAP settings for the current profile called $TemplateName
    
    $Connection = Get-VpnConnection -Name $TemplateName
    
    if(!$Connection)
    {
        $Message = "Unable to get $TemplateName connection profile: $_"
        Write-Host "$Message"
        exit
    }
    
    $EAPSettings= $Connection.EapConfigXmlStream.InnerXml
    
    $ProfileNameEscaped = $ProfileName -replace ' ', '%20'
    
    # Define ProfileXML
    $ProfileXML = @("
    <VPNProfile>
      <DnsSuffix>$DnsSuffix</DnsSuffix>
      <NativeProfile>
    <Servers>$Servers</Servers>
    <NativeProtocolType>IKEv2</NativeProtocolType>
    <Authentication>
      <UserMethod>Eap</UserMethod>
      <Eap>
        <Configuration>
        $EAPSettings
        </Configuration>
      </Eap>
    </Authentication>
    <RoutingPolicyType>SplitTunnel</RoutingPolicyType>
      </NativeProfile>
    <AlwaysOn>true</AlwaysOn>
    <RememberCredentials>true</RememberCredentials>
    <TrustedNetworkDetection>$TrustedNetwork</TrustedNetworkDetection>
      <DomainNameInformation>
    <DomainName>$DomainName</DomainName>
    <DnsServers>$DNSServers</DnsServers>
    </DomainNameInformation>
    </VPNProfile>
    ")
    
    #Output the XML for possible use in Intune
    $ProfileXML | Out-File -FilePath ($env:USERPROFILE + '\desktop\VPN_Profile.xml')
    
    # Escape special characters in the profile (<,>,")
    $ProfileXML = $ProfileXML -replace '<', '&lt;'
    $ProfileXML = $ProfileXML -replace '>', '&gt;'
    $ProfileXML = $ProfileXML -replace '"', '&quot;'
    
    # Define WMI-to-CSP Bridge properties
    $nodeCSPURI = "./Vendor/MSFT/VPNv2"
    $namespaceName = "root\cimv2\mdm\dmmap"
    $className = "MDM_VPNv2_01"
    
    try
    {
    
        # Determine user SID for VPN profile.
        $WmiLoggedOnUsers = (Get-WmiObject Win32_LoggedOnUser).Antecedent
        If($WmiLoggedOnUsers.Count -gt 1) { 
            $WmiLoggedOnUsers = $WmiLoggedOnUsers -match "Domain=""$Domain"""
        }
    
        $WmiUserValid = ($WmiLoggedOnUsers | Select-Object -Unique -First 1) -match 'Domain="([^"]+)",Name="([^"]+)"'
    
        If(-not $WmiUserValid){
            Throw "Returned object is not a valid WMI string"
        }
    
    
        $UserName = "$($Matches[1])\$($Matches[2])"
    
        $ObjUser = New-Object System.Security.Principal.NTAccount($UserName)
        $Sid = $ObjUser.Translate([System.Security.Principal.SecurityIdentifier])
        $SidValue = $Sid.Value
        $Message = "User SID is $SidValue."
    
        Write-Host "$Message"
    
    }
    catch [Exception] 
    {
    
        $Message = "Unable to get user SID. $_"
        Write-Host "$Message" 
        exit
    }
    
    try 
    {
        # Define WMI session.
        $session = New-CimSession
        $options = New-Object Microsoft.Management.Infrastructure.Options.CimOperationOptions
        $options.SetCustomOption("PolicyPlatformContext_PrincipalContext_Type", "PolicyPlatform_UserContext", $false)
        $options.SetCustomOption("PolicyPlatformContext_PrincipalContext_Id", "$SidValue", $false)
    
    }
    catch {
    
        $Message = "Unable to create new session for $ProfileName profile: $_"
        Write-Host $Message
        exit
    }
    
    try
    {
        #Detect and delete previous VPN profile.
        $deleteInstances = $session.EnumerateInstances($namespaceName, $className, $options)
    
        foreach ($deleteInstance in $deleteInstances)
        {
            $InstanceId = $deleteInstance.InstanceID
            if ("$InstanceId" -eq "$ProfileNameEscaped")
            {
                $session.DeleteInstance($namespaceName, $deleteInstance, $options)
                $Message = "Removed $ProfileName profile $InstanceId" 
                Write-Host "$Message"
            }
            else 
            {
                $Message = "Ignoring existing VPN profile $InstanceId"
                Write-Host "$Message"
            }
        }
    }
    catch [Exception]
    {
        $Message = "Unable to remove existing outdated instance(s) of $ProfileName profile: $_"
        Write-Host $Message
        exit
    
    }
    
    try
    {
        # Create the VPN profile.
        $newInstance = New-Object Microsoft.Management.Infrastructure.CimInstance $className, $namespaceName
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("ParentID", "$nodeCSPURI", "String", "Key")
        $newInstance.CimInstanceProperties.Add($property)
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("InstanceID", "$ProfileNameEscaped", "String", "Key")
        $newInstance.CimInstanceProperties.Add($property)
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("ProfileXML", "$ProfileXML", "String", "Property")
        $newInstance.CimInstanceProperties.Add($property)
        $session.CreateInstance($namespaceName, $newInstance, $options)
    
        $Message = "Created $ProfileName profile."
        Write-Host "$Message"
    
    }
    catch [Exception]
    {
    
        $Message = "Unable to create $ProfileName profile: $_"
        Write-Host "$Message"
        exit
    }
    
    $Message = "Script Complete"
    Write-Host "$Message"
    
    
  4. スクリプトの上部にある変数 $Domain$TemplateName$ProfileName$Servers$DnsSuffix$DomainName$DNSServers の値を設定します。 これらの変数を設定する方法の詳細については、「VPNv2 CSP」を参照してください。

  5. Enter キーを押してスクリプトを実行します。

  6. Windows PowerShell ISE で次のコマンドを実行して、スクリプトが成功したことを確認します。

        Get-CimInstance -Namespace root\cimv2\mdm\dmmap -ClassName MDM_VPNv2_01
    
  7. 次の出力が表示されます (読みやすいように ProfileXML 値は省略されています)。

    
    AlwaysOn                : True
    ByPassForLocal          : 
    DeviceTunnel            : 
    DnsSuffix               : corp.contoso.com
    EdpModeId               : 
    InstanceID              : Contoso%20AlwaysOn%20VPN
    LockDown                : 
    ParentID                : ./Vendor/MSFT/VPNv2
    ProfileXML              : <VPNProfile>...</VPNProfile>
    RegisterDNS             : 
    RememberCredentials     : True
    TrustedNetworkDetection : corp.contoso.com
    PSComputerName          : 
    `
    

これで、Always On VPN 用にユーザー トンネルが構成されました。 デバイス トンネルを構成する方法については、「Windows クライアントで VPN デバイス トンネルを構成する」を参照してください。

次のステップ