Mattw11486 Posted August 22, 2021 Posted August 22, 2021 (edited) I am trying to create a tool that creates robotic IDs across multiple domains without having to manually switch to each domain in AD to create the account. It works flawlessly however one issue is that if the username does not exist in AD it throws an error when trying to execute -Manager "employeeid" in Powershell. I tried to remedy this by using the _AD_ObjectExists but I am having some issues with getting it to actually work if the ID does not exist in the domain. Any thoughts on how I am entering this wrong? Thanks! Edited August 23, 2021 by Mattw11486
water Posted August 22, 2021 Posted August 22, 2021 I would use: If _AD_ObjectExists($sObject) = 1 Then ; Object exits If @error = 0 Then ; Only one object exists and no other error occurred $Managercheck = ' -Manager "' & $sOwner & '"' Else $Managercheck = ' ' EndIf EndIf My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Mattw11486 Posted August 23, 2021 Author Posted August 23, 2021 (edited) When running that command it still tries to enter the -Manager $sOwner string, instead of leaving it blank, if a user does not have an ID in that domain. Edited August 23, 2021 by Mattw11486
water Posted August 23, 2021 Posted August 23, 2021 I think one problem is caused in the code block for the "LUV Domain" as the Manager is hard coded there. To solve the second problem you need to connect to the domain you want to check the user for existance. I don't see a call to _AD_Open in your code snippet. So I assume your script always queries the domain you are connected to (by default). My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted August 23, 2021 Posted August 23, 2021 Another suggestion for problem #2: Connect to the global catalog (see the wiki). This allows to query all domains in the forest.https://en.wikipedia.org/wiki/Active_Directory My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now