![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
Disable or Enable user account via powershell scriptthis thread has 8 replies and has been viewed 40731 times
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
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 + "'"
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |