In this Lab We Will:
- Utilize the .json file created in Lab_05 to:
- Create users on the system
- Delete these users from the system
We’ll be utilizing the New-LocalUser cmdlet in our script this time. Reviewing how this cmdlet works from Lab_04 here might be a good idea.
In VSCode let’s create a new script called Gen_Users.ps1. Choose File→New File and type powershell.

We’ll put this in the same folder as the .JSON file we generated in the last lab. Let’s call this file Gen_Users.ps1

Here is the first code snippet we’ll utilize:
- We are going to require that this script be run with a parameter that we’ll call $JSONFile.
- Any time this script is run, the location of the jsonfile we created in the last lab must be utilized as a parameter.
Here is the code to start:
param ([Parameter(Mandatory = $true)] $JSONFile)
#Comment: This can be put at the top of PowerShell scripts to indicate
#Comment: that a Parameter must be used
$users = get-content $JSONFile | convertFrom-json
#Comment: This line gets the content of the $JSONFile and loads it into a variable
$users
#Comment: Here we are printing the variable to test that it works.

If you click the green arrow to run this file (try it now) it will ask you to provide a parameter.

Quit the prompt with CTRL-C
CTRL-C
To run this script, we’ll have to do it from the command line. At your PowerShell prompt, you can run the script like this:
.\\Gen_users.ps1 .\\userlist.json
