4
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellメモ ADユーザー・グループの参照、作成

Last updated at Posted at 2016-12-20

コード

ユーザー情報表示
Import-Module ActiveDirectory

# 全ユーザーを表示
Get-ADUser -Filter * -Properties * | 
    Select-Object displayName,name,enabled,sAMAccountName,userPrincipalName,emailAddress,canonicalName | 
    Out-GridView

# "User"で始まるユーザーを表示
Get-ADUser -Filter {sAMAccountName -like "User*"} -Properties * | 
    Select-Object displayName,name,enabled,sAMAccountName,userPrincipalName,emailAddress,canonicalName | 
    Out-GridView
グループ情報表示
Import-Module ActiveDirectory

# 全グループを表示
Get-ADGroup -Filter * -Properties * | 
    Select-Object displayName,name,sAMAccountName,GroupCategory,GroupScope,mail,member | 
    Out-GridView
ユーザー作成
Import-Module ActiveDirectory

<#
ユーザー「ADUser001」の作成
  □ユーザーは次回ログオン時にパスワード変更が必要
  □ユーザーはパスワードを変更できない
  ■パスワードを無期限にする
  □アカウントは無効
# >
$password1 = ConvertTo-SecureString -AsPlainText "akuD3!%fjzi0lnQ#" -Force
New-ADUser -Name ADUser001 -DisplayName ユーザー1 -ChangePasswordAtLogon $false -CannotChangePassword $false -PasswordNeverExpires $true -Enabled $true -AccountPassword $password1 -Description "○○用のユーザー"


# OU作成
New-ADOrganizationalUnit -Name TestOU -ProtectedFromActidentalDeletion $true
# 大量にユーザー作成(TestUser_00001~TestUser_15000)
$password2 = ConvertTo-SecureString -AsPlainText "test#pswd123%zo0Ol1i" -Force
1..15000 | ForEach-Object {
    [string]$userName = "TestUser_{0:D5}" -f $_
    [string]$dispName = "テストユーザ―_{0:D5}" -f $_

    New-ADUser -Name $userName -DisplayName $dispName -Path "OU=TestOU,DC=testDc,DC=local"  -ChangePasswordAtLogon $false -CannotChangePassword $false -PasswordNeverExpires $true -Enabled $true -AccountPassword $password2 -Description "テスト用のユーザー"
}
グループ作成
Import-Module ActiveDirectory

# グループの作成
New-ADGroup -Name Group001 -DisplayName グループ1 -GroupScope Universal -GroupCategory Security -Description "ユニバーサルセキュリティグループ"
New-ADGroup -Name Group002 -DisplayName グループ2 -GroupScope Global -GroupCategory Distribution -Description "グローバル配布グループ"
New-ADGroup -Name Group003 -DisplayName グループ3 -sAMAccountName SAM_Group003 -OtherAttribute @{'mail'='group003mail@hoge.piyo.jp'; 'mailNickName'='nnGroup003'} -GroupScope Universal -GroupCategory Security

# グループへのメンバ追加
Add-ADGroupMember -Identity Group001 -Members User_A, User_B

参考サイト

4
15
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
4
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?