0
1

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 3 years have passed since last update.

ADユーザー、グループ作成とRFC2307マッピングをパワーシェルで設定する

Last updated at Posted at 2021-05-11

自分の備忘です。

###グループ作成
New-ADGroup -Name "g1" -GroupScope Global

###ADユーザー作成と最低限の設定
#####パスワードが平文で入っているので注意!
New-ADUser -Name "u1" -AccountPassword (ConvertTo-SecureString "PASSWORD1234" -AsPlainText -Force) -Enabled $true -GivenName "u1" -PasswordNeverExpires $true -UserPrincipalName "u1@datacore.jp"

###ユーザーをグループに追加
Add-ADGroupMember -Identity "g1" -Members "u1"

###プライマリグループの変更
#####さっき作ったグループのSIDを取得
$Group = Get-ADGroup "g1"
$GroupSID = $Group.sid
#####最後の数桁だけ(=ID)を切り出す
$GroupID = $GroupSID.value.Substring($GroupSID.value.LastIndexOf("-")+1)
#####プライマリーグループを変更する
Get-ADUser "u1" | Set-ADObject -Replace @{PrimaryGroupID = "$GroupID"}

###RFC2307?(uidNumberとgidNumber)を設定する
Get-ADUser "u1" | Set-ADObject -Replace @{uidNumber = "12345"}
Get-ADGroup "g1" | Set-ADObject -replace @{gidNumber = "12345"}

##これを連続で書くと
あとで気が向いたらグループ名とユーザー名を変数にして取り出す。
あろで気が向いたらプライマリグループのところを1行に書き直す。

New-ADGroup -Name "g1" -GroupScope Global
New-ADUser -Name "u1" -AccountPassword (ConvertTo-SecureString "PASSWORD1234" -AsPlainText -Force) -Enabled $true -GivenName "u1" -PasswordNeverExpires $true -UserPrincipalName "u1@datacore.jp"

Add-ADGroupMember -Identity "g1" -Members "u1"

$Group = Get-ADGroup "g1"
$GroupSID = $Group.sid
$GroupID = $GroupSID.value.Substring($GroupSID.value.LastIndexOf("-")+1)
Get-ADUser "u1" | Set-ADObject -Replace @{PrimaryGroupID = "$GroupID"}

Get-ADUser "u1" | Set-ADObject -Replace @{uidNumber = "12345"}
Get-ADGroup "g1" | Set-ADObject -replace @{gidNumber = "12345"}
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?