LoginSignup
4
7

More than 5 years have passed since last update.

Active Directory, Office365用Powershellコマンド チートシート

Posted at

自分用メモ。よく使うオプションとセットで記録。随時更新。

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}

その他 PowerShell系コマンド

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