PowerShell: Create Local User Account

前端 未结 5 2042
情歌与酒
情歌与酒 2020-12-13 03:44

I need to create a new local user account, and then add them to the local Administrators group. Can this be done in PowerShell?

EDIT:



        
5条回答
  •  囚心锁ツ
    2020-12-13 04:27

    As of PowerShell 5.1 there cmdlet New-LocalUser which could create local user account.

    Example of usage:

    Create a user account

    New-LocalUser -Name "User02" -Description "Description of this account." -NoPassword
    

    or Create a user account that has a password

    $Password = Read-Host -AsSecureString
    New-LocalUser "User03" -Password $Password -FullName "Third User" -Description "Description of this account."
    

    or Create a user account that is connected to a Microsoft account

    New-LocalUser -Name "MicrosoftAccount\usr name@Outlook.com" -Description "Description of this account." 
    

提交回复
热议问题