Check user exist in AD with powershell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 01:37 AM
I have a condition to check if user exist in AD so that while rehiring we do not create a new userid for the same user who has a deactivated account and reactivate the same account.
I found ways to to do that via AD activities but that uses LDAP.
I do not have LDAP and want to do the same via powershell script.
Can anyone help how to do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 01:51 AM
I think as a pre-requisite you need to have RSAT Installed on a machine from where you would like to query AD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 01:59 AM
We have it but i need powershell script and not use ad activities.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 03:11 AM
Here is an example:
Import-Module Activedirectory
$newusers = @("john.snow","ned.stark01","tyron.lannister")
foreach ($newuser in $newusers)
{
if (Get-aduser $newuser)
{
write-host "$newuser already exists"
}
else
{
New-aduser -samaccountname $newuser
}
}
For more information consult this page:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 07:34 AM
avanis please mark the reply as Answered.