Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Add Displayname and password neverchanges to PS script

$
0
0

I would like to add DispalyName and Password never changes (I did not add this attribute) to PS script. This script will add users from a csv file from excel. Here is my script. It works except when I add the DisplayName I get an error. 

 

Import-Module ActiveDirectory

Import-Csv "C:\Scripts\NewUsers.csv" | ForEach-Object {

 $userPrincinpal = $_."samAccountName" + "@doman.Local"

New-ADUser -Name $_.Name `

 -Path $_."ParentOU" `

 -SamAccountName  $_."samAccountName" `

 -UserPrincipalName  $userPrincinpal `

 -AccountPassword (ConvertTo-SecureString "12345678" -AsPlainText -Force) `

 -ChangePasswordAtLogon $true  `

 -Enabled $true

 -DisplayName $_."DisplayName"

Add-ADGroupMember "Students" $_."samAccountName";


Viewing all articles
Browse latest Browse all 6937

Trending Articles