自分用メモ。よく使うオプションとセットで記録。随時更新。
Active Directory
ユーザー関連
New-ADUser
New-ADUser -Name "Name" -Path "Path" -UserPrincipalName "Email" -EmailAddress "Email" -AccountPassword (ConvertTo-SecureString "Password" -AsPlainText -force) -DisplayName "Name" -Surname "SurName" -GivenName "GivenName" -Enabled $true -ChangePasswordAtLogon $false
こんなCsvを用意すると
sample.csv
Name,Path,Email,Password,SurName,GivenName,SamAccountName
Taro Suzuki,"CN=Users,DC=corp,DC=sample,DC=com",taro.suzuki@example.com,P@ssw0rd,Suzuki,Taro,taro.suzuki
バッチ作成出来る
Import-Csv sample.csv | ForEach-Object {New-ADUser -Name $_.Name -Path $_.Path -UserPrincipalName $_.Email -EmailAddress $_.Email -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -DisplayName $_.Name -Surname $_.SurName -GivenName $_.GivenName -Enabled $true -ChangePasswordAtLogon $false}
Get-ADUser
example.comの人を取得する
Get-ADUser -Filter {EmailAddress -like "*@example.com"}
全プロパティ取得
Get-ADUser -Filter {EmailAddress -like "*@example.com"} -Properties *
Set-ADUser
Under editing...
New-ADGroup
New-ADGroup -Name "Name" -GroupGategory Security -GroupScope Global -OtherAttributes @{Mail="test@example.com"}
Get-ADGroup
Get-ADGroup "group_name" -Properties *
Office365
使う前に
Connect-MsolService
Set-MsolUser
ユーザーのロケーション設定 (sample.csvでバッチ処理)
Import-Csv sample.csv | ForEach-Object {Set-MsolUser -UserPrincipalName $_.Email -UsageLocation JP}
Set-MsolUserLicense
ライセンスの付与
Import-Csv sample.csv | ForEach-Object {Set-MsolUserLicense -UserPrincipalName $_.Email -AddLicense "sample:SMB_BUSINESS_ESSENTIALS"}
Set-MsolUserPassword
パスワードリセット
Import-Csv sample.csv | ForEach-Object {Set-MsolUserPassword -UserPrincipalName $_.Email -NewPassword xxxxx}