locked
Powershell script to change account expiration RRS feed

  • Question

  • Hello,

    I'm very new at scripting but I have the following script

    Import-Module ActiveDirectory

    import-csv C:\Users\jpratt\Desktop\book1.csv |
    ForEach{
    #set expiration date

    $expire = read-host -prompt "Should this account expire y/n"
    if ($expire -eq "y") {
    $expirationdate = read-host -prompt "enter expiration date mm/dd/yy"
    $time = [datetime]"$expirationdate" - (Get-Date)
    $days = $time.days
    Write-Host $days
    dsmod user "$userDN" -acctexpires $days
     }
     }

    I am getting a DSMOD error so Im thinking it is something simple im overlooking.  I do get the popup asking me to input the date I want it to expire.

    Thanks for any help,


    • Edited by Cloud2819 Monday, March 17, 2014 4:15 PM Wrong script
    Monday, March 17, 2014 3:47 PM

Answers

  • DSMOD is only installed on domain controllers or on systems with remote admin tools installed.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Monday, June 9, 2014 8:12 PM
    Monday, March 17, 2014 5:06 PM

All replies

  • Hi,

    What's your question? Does that script you've posted make sense to you or are you completely in the dark?


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Monday, March 17, 2014 3:57 PM
  • The script makes sense.  If I have an account that expires March 30th and I type in 90 days it extends the account another 90 days from that point.  What I cant seem to do is make it so instead of just typing in 90 days I rather type in something like 6/30/2014 and have it extend the date that way.  But I cant seem to make it work 
    Monday, March 17, 2014 4:03 PM
  •  But I cant seem to make it work 

    Okay, so what have you tried? What errors are you getting?


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Monday, March 17, 2014 4:07 PM
  • Sorry I pasted the wrong script.  The new script is what im trying to make work but I keep getting a DSMOD error even though from what I look up it appears correct to me.  it pops up asking for the date like it should 
    Monday, March 17, 2014 4:16 PM
  • Let me guess.  The error is "access denied".  You are not an admin?


    ¯\_(ツ)_/¯

    Monday, March 17, 2014 4:30 PM
  • The term 'dsmod' 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.
    At line:11 char:8
    +   dsmod <<<<  user "$_" -acctexpires $days
        + CategoryInfo          : ObjectNotFound: (dsmod:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    that is the Error.  If I put CMD infront of DSMod the script runs but wont update the AD account 

    Monday, March 17, 2014 4:37 PM
  • The error message tells you what's wrong:

    The term 'dsmod' 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.

    This means that PowerShell can't find the command. Type this command at the PowerShell prompt:


    get-command dsmod

    If you don't get anything back, then dsmod.exe is not available in your path, or your path is broken.

    Alternatively, you can not use dsmod.exe at all and just use set-aduser (-AccountExpirationDate parameter).


    -- Bill Stewart [Bill_Stewart]


    Monday, March 17, 2014 4:51 PM
  • DSMOD is only installed on domain controllers or on systems with remote admin tools installed.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Monday, June 9, 2014 8:12 PM
    Monday, March 17, 2014 5:06 PM