Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > Powershell
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Disable or Enable user account via powershell script

Disable or Enable user account via powershell script

this thread has 8 replies and has been viewed 40731 times

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 23rd June 2008, 16:32
XtaZee XtaZee is offline
Casual
It's not a coincidence
 
 Join Date: Jan 2005
  6 month star 12 month star
 Posts: 71
 Reputation: XtaZee is on a distinguished road (33)
Default Disable or Enable user account via powershell script

Hi,
Looking for a script that enable or disable a user account via PowerShell v1

the script should be given 2 parameters username and state (enable/disable)

so far I have a little code that will search for the user in ldap

Code:
function get-dn ($SAMName)
{
 	$root = [ADSI]''
 	$searcher = new-object     System.DirectoryServices.DirectorySearcher($root)
	$searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))"
	$user = $searcher.findall()

	if ($user.count -gt 1)
      {     
            $count = 0
            foreach($i in $user)
            { 
			write-host $count ": " $i.path 
                  $count = $count + 1
            }

            $selection = Read-Host "Please select item: "

return $user[$selection].path

      }
      else
      { 
	  	return $user[0].path
      }
}

$Name = $args[0]
$path = get-dn $Name
"'" + $path + "'"
your 2 cents will be mostly welcome...
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable User in Live Communications Server Fails (Was:enable lcp user failed) h7h Windows Server 2000 / 2003 1 1st May 2007 12:07
I script was made by on of our administrator to disable any computer account noway Active Directory 3 18th July 2006 12:16
Disable Active Directory user account Lucide General Scripting 2 17th November 2005 16:30
Problems w/ unlock user account script in Active Directory Shane General Scripting 1 25th July 2005 23:29
Disable.Group.User.Account azmantek Active Directory 3 28th October 2004 19:52


All times are GMT +3. The time now is 07:50.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri