-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNew-LocalAdminAccount.ps1
More file actions
20 lines (15 loc) · 923 Bytes
/
Copy pathNew-LocalAdminAccount.ps1
File metadata and controls
20 lines (15 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# New-LocalAdminAccount.ps1
# Creates a local administrator account that never expires
# Must be run as Administrator
# --- Configuration ---
$AccountName = "<AccountName>" # e.g., "LocalAdmin"
$Password = "<Password>" # e.g., "P@ssw0rd123" (consider prompting instead)
# ---------------------
# Prompt for password securely (recommended - uncomment to use)
# $SecurePass = Read-Host "Enter password for $AccountName" -AsSecureString
# $Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
# [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePass))
Write-Host "--- Creating Local Admin Account: $AccountName ---" -ForegroundColor Cyan
C:\Windows\System32\net.exe user $AccountName $Password /Add /Expires:Never
C:\Windows\System32\net.exe LocalGroup Administrators $AccountName /Add
Write-Host "Account '$AccountName' created and added to Administrators group." -ForegroundColor Green