コード
ユーザー情報表示
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