Hello group I am new to Power-Shell and am trying to learn at a fair speed. Trying to take some code and modify it. Any help would be great.
I have some basic codding See Errors
-Path : The term ‘-Path’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is correct and try again.
What am i missing here.
See Code below:
Enabled the execution of all scripts - disables a sercurity policy
Set-ExecutionPolicy Unrestricted
Import active directory module for running AD cmdlets
Import-Module activedirectory
Password for users variables
$PASSWORD_FOR_USERS = “Welcome!1qaz”
Takes the names from the names.txt and put them into $USER_…
Note: Your PS C: prompt has to be run from the directory when the text names is in.
$USER_FIRST_LAST_LIST = Get-Content .\names.txt
Takes password and converts it to plaintext
$password = ConvertTo-SecureString $PASSWORD_FOR_USERS -AsPlainText -Force
creates a new org ion AD only if the Import-Module activedirectory cmd has been run
New-ADOrganizationalUnit -Name ‘Test Users’ -ProtectedFromAccidentalDeletion $false
$n is the user in the names.txt list.
The code will split the first and last name make them lowercase and store in the variables $Firstname etc.
foreach ($n in $USER_FIRST_LAST_LIST) {
$firstname = $n.Split(" “)[0].ToLower()
$lastname = $n.Split(” ")[1].ToLower()
$username = “$($firstname).$($lastname)”.ToLower()
Gives an output of the names.
Write-Host "Creating user: $($username)" -BackgroundColor Black -ForegroundColor Cyan
New-ADUser -AccountPassword $password `
-EmployeeID $username `
-PasswordNeverExpires $false `
-SamAccountName $username `
-UserPrincipalName "$username@mybdomain.com" `
-Name "$firstname $lastname" `
-GivenName $firstname `
-Surname $lastname `
-DisplayName "$lastname, $firstname" `
# -Path $OU `
#-City $city `
-Company $company `
-State $state `
-StreetAddress $streetaddress `
-OfficePhone $telephone `
-EmailAddress $email `
-Title $jobtitle `
-Department $department `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True
-Path "ou=Test Users,$(([ADSI]`"").distinguishedName)" `
-Enabled $true
}