1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

個人的備忘録:PowerShell・GUI・Linux コマンドで簡単に確認する LDAP 認証の技術検証をまとめてみた

Last updated at Posted at 2025-03-08

はじめに

LDAP 認証を確認する際、できるだけ簡単に素早くチェックできる方法を知っておくと便利です。

この記事では PowerShell、GUI(ldp.exe)、Linux(ldapsearch)を使った LDAP 認証の確認方法を解説します。


方法 1: PowerShell を使って LDAP 認証を確認

PowerShell のワンライナーコマンドで LDAP 認証をすばやく確認できます。

コマンド

(New-Object DirectoryServices.DirectoryEntry("LDAP://ad.honda.com", "honda-admin@honda.com", "honda")).Name

成功時の出力

CN=Honda Admin

LDAP 認証が成功し、ユーザー情報が取得できています。

失敗時の出力

Exception calling ".ctor" with "3" argument(s): "The user name or password is incorrect."

➡ ユーザー名やパスワードが間違っている可能性があるので確認してください。


方法 2: ldp.exe を使う(GUI で確認)

PowerShell に慣れていない場合は、Windows に標準搭載されている ldp.exe を使用できます。

手順

  1. 「Windowsキー + R」を押して ldp.exe と入力 → Enter
  2. 「Connection」→「Connect」を選択
    • Server: ad.honda.com
    • Port: 389(LDAPS を使う場合は 636
    • Use SSL → チェックなし (636 を使う場合はチェック)
  3. 「Connection」→「Bind」を選択
    • User: honda-admin@honda.com
    • Password: honda
  4. 「OK」をクリックして認証を試す

成功時

Authenticated as DN のメッセージが表示

失敗時

Invalid credentials エラーが表示


方法 3: ldapsearch を使う(Linux / WSL)

Linux や Windows の WSL (Ubuntu) を使用している場合、ldap-utils をインストールすれば、ldapsearch コマンドで LDAP 認証を確認できます。

コマンド

ldapsearch -x -H ldap://ad.honda.com -D "honda-admin@honda.com" -w "honda" -b "DC=honda,DC=com"

成功時の出力

# honda-admin, Users, honda.com
dn: CN=Honda Admin,CN=Users,DC=honda,DC=com
objectClass: user
sAMAccountName: honda-admin

失敗時の出力

ldap_bind: Invalid credentials (49)

➡ パスワードが間違っているか、LDAP サーバーのアクセス制限がある可能性があります。


まとめ

方法 コマンド 成功時の表示
PowerShell (ワンライナー) (New-Object DirectoryServices.DirectoryEntry("LDAP://ad.honda.com", "honda-admin@honda.com", "honda")).Name CN=Honda Admin
GUI (ldp.exe) ldp.exe → 「Bind」 Authenticated as DN
Linux / WSL (ldapsearch) ldapsearch -x -H ldap://ad.honda.com -D "honda-admin@honda.com" -w "honda" -b "DC=honda,DC=com" dn: CN=Honda Admin, CN=Users, DC=honda, DC=com

おまけ:追加情報の取得

LDAP 認証が成功したら、ユーザー情報の詳細を取得できます。

① 完全な DN (Distinguished Name) を取得

(New-Object DirectoryServices.DirectoryEntry("LDAP://ad.honda.com", "honda-admin@honda.com", "honda")).Properties["distinguishedName"].Value

② sAMAccountName (ログインID) を取得

(New-Object DirectoryServices.DirectoryEntry("LDAP://ad.honda.com", "honda-admin@honda.com", "honda")).Properties["sAMAccountName"].Value

③ すべての属性を一覧表示

$ldapUser = New-Object DirectoryServices.DirectoryEntry("LDAP://ad.honda.com", "honda-admin@honda.com", "honda")
$ldapUser.Properties.PropertyNames | ForEach-Object { "$_ : " + $ldapUser.Properties[$_] }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?