Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Check user exist in AD with powershell

avanis
Kilo Contributor

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.

13 REPLIES 13

{


      "hresult": "-2146233088",


      "output": "\n",


      "errorMessages": "\nCannot find an object with identity: 'F090900' under: 'DC=eu,DC=t-u,DC=outer'.Stack Trace:       at Microsoft.ActiveDirectory.Management.Commands.ADFactoryUtil.GetObjectFromIdentitySearcher(ADObjectSearcher searcher, ADEntity identityObj, String searchRoot, AttributeSetRequest attrs, CmdletSessionInfo cmdletSessionInfo, String[]& warningMessages)at Microsoft.ActiveDirectory.Management.Commands.ADFactory`1.GetExtendedObjectFromIdentity(T identityObj, String identityQueryPath, ICollection`1 propertiesToFetch, Boolean showDeleted)at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.ProcessRecordOverride()at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase.ProcessRecord()\n",


      "eccSysId": "e02d42766f74c30005360519ea3ff4ea",


      "tags": {


              "__text__": "\n"


      }


}


Hi Avani,



For using AD and powershell you want to have LDAP present in the instance.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

adilrathore
ServiceNow Employee
ServiceNow Employee

I checked the discussions on the form and it seems to be a credential issue. Check the below discussion:



To add/remove users into an Active Directory group


But since it is working fine when user exist, how can it be a credential issue.


Its just that when IF is not working, it is not going in else.