Powershell によるAD ユーザーの一括登録 (改訂版)
<準備>
・WindowsServer2008R2
・「Active Directory サービス」(役割)のインストール、設定
・「Windows Powershell用のActive Directoryモジュール」(機能)のインストール
・「PowerShell」のヴァージョンアップ ( V.2 —> V.4.0 )
1)Microsoft Download Centerから「.Net Framework 4.5以降」を入手しインストール
(Windows Update有効の場合はインストール済みか?)
2)同上から「Windows Management Framework 4.0」を入手、インストール
<手順>
・「UserData.txt」ファイルの設置 (例:C:\直下に)
——C:\UserData.txt———
Name,UserPrincipalName,SamAccountName,Path,Description
Yoshi Oshima,Yoshi_Oshima@tcoffice.virtual,Yoshi_Oshima,”CN=Users,DC=tcoffice,DC=virtual”,練習テスト用
Kaku Kobayashi,Kaku_Kobayashi@tcoffice.virtual,Kaku_Kobayashi,”CN=Users,DC=tcoffice,DC=virtual”,練習テスト用
Sari Suzuki,Sari_Suzuki@tcoffice.virtual,Sari_Suzuki,”CN=Users,DC=tcoffice,DC=virtual”,練習テスト用
Misa Shimazoe,Misa_Shimazoe@tcoffice.virtual,Misa_SHimazoe,”CN=Users,DC=tcoffice,DC=virtual”,練習テスト用
……
…..
・「スタート」→「管理ツール」→「Windows Powershell用のActive Directoryモジュール」の起動
・コマンドレット実行権限の確認
PS> Get-ExecutionPolicy // Restricted の場合に RemoteSigned に変更する
PS> Set-ExecutionPolicy RemoteSigned
・Csvファイルをインポートし、ADユーザ追加のコマンドレットの実行
——–PS—————–
PS >Import-Csv C:\UserData.txt | New-ADUser `
>>-AccountPassword ( ConvertTo-SecureString ‘P@ssw0rd’ -AsPlainText -Force ) `
>>-Enabled $true
>>
・「練習テスト用」ユーザを抽出し、ADユーザ設定のコマンドレットの実行
PS > Get-ADUser -Filter ‘Description -eq “練習テスト用” | Set-ADUser `
>>-ChangePasswordAtLogon $true
>>
以上。—————–