Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

-password never expires

$
0
0

Hi everyone,

i have to add users by using these commands:

With that i want the password never to expire by using PS commands how do i do that i have tried alot of things

#New-Item -Path C:\Users\Administrator\Documents\ -Name homefolder -ItemType directory 
Clear-Host
New-ADGroup -GroupScope Global -Name TEST -Path 'OU=Testomgeving,DC=MediaTech,DC=lan' 
New-ADOrganizationalUnit -Name Testomgeving

$Users = Import-Csv -Path 'C:\Users\Administrator\Documents\Namenlijst ps 9.1.csv' 
ForEach ($User in $Users)

{
$Fulname = $User.Firstname + " " + $User.Lastname
$Firstname = $User.Firstname
$Lastname = $User.Lastname
$domain = "@mediatech.lan" 
$upn = $User.Lastname + $domain
$OU = $User.OU
$Password = $User.Password
$driveletter = "H:"
$Homefolder = $User.Homefolder
$setPassword = (ConvertTo-SecureString $Password -AsPlainText -Force)
$PhoneNumber = $User.Phone 

echo $PhoneNumber

New-ADUser -Name $Firstname -Surname $Lastname -DisplayName $Fulname `
-GivenName $Firstname -SamAccountName $Lastname -HomeDrive $driveletter `
-HomeDirectory $Homefolder -UserPrincipalName $upn -Path $OU -OfficePhone "$PhoneNumber" -HomePhone "$PhoneNumber" -MobilePhone "$PhoneNumber" `
-AccountPassword $setPassword -Enabled $True -PassThru `
-Department 'TEST' -Company 'MediaTech' `
-PasswordNeverExpires
}

then i get this warning: 

New-ADUser : Missing an argument for parameter 'PasswordNeverExpires'. Specify a parameter of type 'System.Nullable`1[System.Boolean]' and try again.
At C:\Users\Administrator\Documents\9.1.ps1:29 char:1
+ -PasswordNeverExpires

`

thank you in advanced.




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>