Windows 10 Local User Creation via PowerShell - How to make it interactive?

Viewed 150

I'm not sure if my problem has been described and resolved in another post, but I haven't found it...

I'm trying to create a PowerShell script to get a Local User Account created on Windows 10 machines that are not in AD nor domain. I want to have the possibility to enter the "first" and "last" names of the new user or at least the "username" and not need to modify this in the PS script file every time before running it.

I tried this code but it doesn't create any new users...

$FirstName = Read-Host -Prompt 'Enter User First Name:'
$LastName = Read-Host -Prompt 'Enter User Last Name:'
$Username=$FirstName.substring(0,1)+$LastName
New-LocalUser $Username -Description "INT-G-MAT Local User" -NoPassword
1 Answers

You could use

New-LocalUser -FullName "Fullname" -AccountNeverExpires $True -Description "Something"

By using ScriptBlock, you can create useraccounts on remote machines. For example

Invoke-Command -ComputerName $Computername -ScriptBlock { # Start ScriptBlock
New-LocalUser -FullName "Fullname" -AccountNeverExpires $True -Description "Something"
} # End Scriptblock

If you want to check what accounts are on the remote machine,

Get-WmiObject -Class Win32_UserProfile 

I would start something like this and then test until I think is acceptable in this script

Invoke-Command -ComputerName "Computername" -ScriptBlock { # Start ScriptBlock
$Fullname = Read-Host -Prompt "Enter User First Name:"
New-LocalUser -FullName $Fullname -AccountNeverExpires $True -Description "Something" -PasswordNeverExpires $True
} # End Scriptblock
Related