Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

powershellでローカルユーザを追加

More than 1 year has passed since last update.

1.概要

powershellでローカルユーザを10人分(内一名はAdmin権限)自動作成するスクリプト。
自分用なので悪しからず。

2.環境

・powershell : 5.1

3.コード

localacc_set.ps1
#ローカルユーザを10人作成
$user_name = "A0001","A0002","A0003","A0004","A0005","A0006","A0007","A0008","A0009","A0010" #ローカルユーザ名
$user_pass_plane = "A_00000001","A_00000002","A_00000003","A_00000004","A_00000005","A_00000006","A_00000007","A_00000008","A_00000009","A_00000010" #ローカルユーザのパスワード

for($i=0; $i -lt $user_name.Length; $i++)
{
    $user_pass_secure = convertto-securestring  $user_pass_plane[$i] -AsPlainText -Force #パスワードを暗号化
    New-LocalUser -Name $user_name[$i] -Password $user_pass_secure  #ローカルユーザを新規作成
    if($i -eq 9)
    {
    Add-LocalGroupMember -Group "Administrators" -Member $user_name[$i] #10人目のみAdmin権限を与える
    }
}

#以下確認用
<#
Set-LocalUser -Name $name -Password $pass_secure -Description $description #ローカルユーザーの情報更新
Remove-LocalUser -Name $name #ローカルユーザの削除
Get-LocalUser # ローカルユーザー取得
Get-LocalGroupMember -Group "Administrators" #Admi権限をもつローカルユーザの取得
Remove-LocalGroupMember -Group "Administrators" -Member $user_name #グループからメンバーを除外
#>
isyt
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away