Create multiple local user accounts with text file and disable them after a period of time time with powershell script.

I don't understand if you need to disable them after 4 hs, or next Monday. 

This is how I would do it:

  • If you need to disable them in a certain amount of time, use the sleep command http://technet.microsoft.com/en-us/library/ee177002.aspx.
  • If you need to disable them next Monday, I would create 2 scripts, one to create them and another one to disable them, and I would configure the second one to run with the task scheduler whenever I want... 

Regards

EDIT: The other one is to create a recursive script, so it stays running until a moment in time, but I wouldn't recommend that.
January 24th, 2014 8:22am

Have a look here...it has a Disable-LocalUserAccount function

http://berkenbile.wordpress.com/2013/04/26/manage-local-user-accounts-with-powershell/

For scheduling them you can create a scheduled task.....

Hope this helps

Free Windows Admin Tool Kit Click here and download it now
January 24th, 2014 8:26am

Hi,

I need a script to create multiple local user accounts using a text file and then disable them after a period of time or disable them at a certain time. 

I managed to create multiple account with the text file, but I can't figure out the way to disable them.

That's what I got so far:

$computer = [System.Net.Dns]::GetHostName()
$text = "C:\Einu\Users.txt"
$user = import-csv -path $text

   foreach($strUser in $user)
    {
     $user = $struser.user
     $password = $struser.password
     $description =  $struser.description
     Clear-Host
     $ObjOU = [ADSI]"WinNT://$computer"
     $User = $objOU.Create("User", $user)
     $User.setpassword($password)
     $User.put("description",$description)
     $User.SetInfo()
     Clear-Host
     }

Einu

users.txt:

user, password, description
auser, asd, amees
buser, asd, bmees
cuser, asd, cmees



  • Edited by Einu 23 hours 56 minutes ago
January 24th, 2014 2:27pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics