Create a file consisting a group of 3 new user name’s and passwords in powershell, 1 to a line. When you read in the line you’ll have to split the name and the password.
a. Write a script in powershell that does the following
i. Use get-content to retrieve the names and assign them to an array
ii. Write a loop that prints out each of the user names.
iii. Have your script create an account using localuser for each of the users Add each of these users to the local group Users
iv. Hand in your script and proof that all of the users listed have been created.
This example gets the content of a file in the current
directory. The LineNumbers.txt
file contains 100 lines
in the format, This is Line X and is used in several examples.
PowerShellCopy
1..100 | ForEach-Object { Add-Content -Path .\LineNumbers.txt -Value "This is line $_." }
Get-Content -Path .\LineNumbers.txt
This is Line 1
This is Line 2
...
This is line 99.
This is line 100.
The array values 1-100 are sent down the pipeline to the
ForEach-Object
cmdlet. ForEach-Object
uses a script block with the Add-Content
cmdlet to
create the LineNumbers.txt
file. The variable
$_
represents the array values as each object is sent
down the pipeline. The Get-Content
cmdlet uses the
Path parameter to specify the LineNumbers.txt
file and
displays the content in the PowerShell console.
Get Answers For Free
Most questions answered within 1 hours.