locked
-password never expires RRS feed

  • Question

  • 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.



    Thursday, January 17, 2019 6:27 PM

Answers

  • -PasswordNeverExpires:$true

    Learn to read the errors and the docs.


    \_(ツ)_/

    Thursday, January 17, 2019 6:34 PM
  • 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 $true   
    }


    Hi Alexander.

    Please see the modification to your code in bold , and also as jrv says just add $true after your
     -PasswordExpires

    Good luck with your case :-)

    Let me know if I can help you more.


    Attention: This posting is provided "AS IS" with no warranties, or guarantees, and confers no rights. Please remember to mark the replies as answers if they are informative and help.

    Thursday, January 17, 2019 6:52 PM

All replies

  • -PasswordNeverExpires:$true

    Learn to read the errors and the docs.


    \_(ツ)_/

    Thursday, January 17, 2019 6:34 PM
  • thank you that solved it

    Thursday, January 17, 2019 6:40 PM
  • 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 $true   
    }


    Hi Alexander.

    Please see the modification to your code in bold , and also as jrv says just add $true after your
     -PasswordExpires

    Good luck with your case :-)

    Let me know if I can help you more.


    Attention: This posting is provided "AS IS" with no warranties, or guarantees, and confers no rights. Please remember to mark the replies as answers if they are informative and help.

    Thursday, January 17, 2019 6:52 PM