Creating hidden user account with administrative privileges using script (PowerShell)

Introduction

This PowerShell script sample shows how to create a hidden user account with administrative privileges.

Scenarios

For the aspect of the security, some users want to hide a user account with administrative privileges, this script can create a hidden user account with administrative privileges.

Script

Step 1: Click Start, type powershell in the search box on the Start Menu, right-click the Windows PowerShell icon, and then click Run Windows PowerShell as administrator. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Continue.
Step 2: Run the script in the Windows PowerShell Console, type the command: Import-Module <Script Path> at the prompt.
For example, type Import-Module C:\Scripts\HiddenUserAccount.ps1
This is shown in the following figure.
Step 3: You can type the command Get-Help New-OSCHiddenAccount –Full to display the entire help file for this function, such as the syntax, parameters, or examples.
 
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
#create a user account 
$objOu = [ADSI]"WinNT://$ComputerName" 
$objUser = $objOU.Create("User", $UserName) 
#set password 
$objUser.SetPassword($Password) 
$objUser.SetInfo() 
  
#set whether the user need to change the passwordIf($PasswordExpired -gt 0) 
{ 
    $objUser.PasswordExpired = $PasswordExpired 
    $objUser.SetInfo() 
} 
Else 
{ 
    $objUser.PasswordExpired = 0 
    $objUser.SetInfo() 
}

Example

Example 1:
To create a hidden user account with administrative privileges, type the command New-OSCHiddenAccount -UserName "Hidden001" -Password "Passowrd01!"

Prerequisite

Windows PowerShell 2.0