0
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?

Active Directory入門:PowerShell で Active Directory のユーザー情報を取得する方法

Last updated at Posted at 2025-03-09

はじめに

Active Directory(AD)のユーザー情報を取得するには、PowerShell を使用すると便利です。本記事では、xxx というユーザーの情報を取得するための簡単な方法を紹介します。


方法 1: Get-ADUser を使用する(推奨)

最も簡単な方法は、PowerShell の Get-ADUser コマンドを使用することです。

Get-ADUser -Identity xxx -Properties *

動作の流れ

  • -Identity xxx : ユーザー xxx の情報を取得します。
  • -Properties * : すべてのプロパティ(名前・メール・所属グループなど)を取得します。

前提条件

  • Active Directory モジュール(RSAT: Remote Server Administration Tools)がインストールされている
  • ドメインコントローラー上で実行する か、ドメイン参加済みの PC で実行する
  • 管理者権限が必要な場合がある

特定の情報だけ取得

例えば、表示する情報を 名前・メール・最終ログイン に絞る場合:

Get-ADUser -Identity xxx -Properties DisplayName, EmailAddress, LastLogonDate |
    Select-Object DisplayName, EmailAddress, LastLogonDate

方法 2: DirectoryServices を使用する

Get-ADUser が使えない環境(Active Directory モジュールがない場合)でも、DirectoryServices を使って情報を取得できます。

$ldapPath = "LDAP://ad.honda.com"
$username = "xxx@honda.com"
$password = "honda"

$entry = New-Object DirectoryServices.DirectorySearcher([ADSI]"$ldapPath")
$entry.Filter = "(&(objectClass=user)(sAMAccountName=xxx))"
$user = $entry.FindOne()

$user.Properties

この方法のポイント

  • LDAP://ad.honda.com に接続して xxx の情報を取得
  • FindOne() で 1 件の結果を取得
  • Properties でユーザーのすべての情報を表示

方法 3: コマンドライン(dsquery / dsget を使用)

PowerShell を使わずに Windows のコマンドプロンプトから取得する場合は、dsquery を使用できます。

dsquery user -name xxx | dsget user -dn -samid -display -email -dept

この方法のポイント

  • dsquery user -name xxx でユーザーの DN (識別名) を取得
  • dsget user -dn -samid -display -email -dept で詳細情報を取得

dsqueryドメイン環境 でのみ動作します。


まとめ

方法 コマンド メリット 注意点
方法1: Get-ADUser(推奨) Get-ADUser -Identity xxx 簡単・詳細な情報が取れる ADモジュールが必要
方法2: DirectoryServices $entry = New-Object DirectoryServices.DirectorySearcher(...) ADモジュールなしでOK 少しコードが長い
方法3: dsquery/dsget `dsquery user -name xxx dsget user` コマンドラインで簡単

どれを試すべき?

  • ドメイン参加済みで PowerShell モジュールが使えるなら Get-ADUser
  • LDAP 経由で取得したいなら DirectoryServices
  • コマンドラインで簡単に取得したいなら dsquery

おわりに

PowerShell を使用すると、Active Directory のユーザー情報を簡単に取得できます。環境に応じて適切な方法を選び、ぜひ活用してください!

もしエラーが出る場合は エラーメッセージ を確認し、適切な対処を行なってみてください!

0
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
0
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?