You're close to getting where you want!
Declaring Arrays: You'll notice that when you try to use $newuser = @(ash, bob, charlie, david) in PowerShell ISE or VSCode, you'll get a syntax error. This is because you need to place quotes around each item. The way you've done it originally is no different in practice. It is simply up to how you want to define arrays. Sometimes with large arrays that expand multiple lines, it can be easier to keep track of where it ends when wrapped with @()
Understanding your variables: You can test the two array declaration methods by trying both ways, and using the GetType() method like so: $newuser.GetType()
Naming Conventions: Try to use plurals for variable names when dealing with something that contains multiple objects, like an array. So in this case, $newuser should be $newusers, and try to make your variables descriptive of what they contain. (You've done that nicely here)
$PSItem and $_: When you iterate over an array, there is a nifty PowerShell variable called $PSItem, also called by alias $_. This variable contains the current object you are iterating over. See the example below for how I might do something like this, but also keep in mind there are multiple ways to accomplish things in PowerShell most of the time.
Passwords: The cmdlet you are using here will not take a string as a password, but instead will require a SecureString. You can force the string to a SecureString in the script, but only do this as practice. The best thing to do is have a file that you call from and shred afterwards or external password manager that you call upon when needed to pass the value. PlainTexting the password is NEVER a good idea.
Method 1
$newUsers = ‘ash’, ‘bob’, ‘charlie’, 'david’
$securePassword = ConvertTo-SecureString '123123' -AsPlainText -Force
foreach ($user in $newUsers) {
New-LocalUser -Name $user -Password $securePassword -Description 'Students'
}
Method 2
$securePassword = ConvertTo-SecureString '123123' -AsPlainText -Force
‘ash’, ‘bob’, ‘charlie’, 'david’ | ForEach-Object {New-LocalUser -Name $PSItem -Password $securePassword -Description 'Students'}
This is mostly personal preference, or you'd follow the standard your team uses, but I'd say the first is what I would use in a script, as I find it a bit more readable, and the second is something I would do on the fly in a terminal.