Mattw11486 Posted October 30, 2018 Posted October 30, 2018 Currently I am working on a prehire auto builder for my company. Essentially what I want it to do is you type in the employee ID of the user and then the database you want their mailbox to go on (depending on their role) Once you hit the "Create Employee" button, I want it to create the mailbox for the user, who already exists in AD/Exchange and also add a SIP account for the user. How would I go about accomplishing this with integrating Powershell/Exchange Management Shell into AutoIT? Everything works minus the shellexecutewait command which I get an error on so I am looking for the correct way to do this. Thanks! My Current Code: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Auto Prehire Tool", 288, 438, 2295, 257) $EmployeeID = GUICtrlCreateInput("EmployeeID", 64, 104, 129, 21) $Radio1 = GUICtrlCreateRadio("Check for F drive Creation", 48, 216, 185, 17) $Database = GUICtrlCreateInput("Database", 32, 160, 209, 21) $Button1 = GUICtrlCreateButton("Create Employee", 72, 320, 163, 57) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $id=GUICTrlRead($EmployeeID) $data=GUICTrlRead($Database) ShellExecuteWait("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command enable-mailbox -identity "&$id&" -database "&$data&"") $CMD = "dsquery user -samid "&$id&"| dsmod user -loscr SWA" RunWait(@ComSpec & " /c " & $CMD) if GUICtrlRead($Radio1) = 1 Then ;~ $CMD = "dsquery user -samid "&$id&"| dsmod user -hmdir \\sdcpflr002\"&$id&" -hmdrv F:" RunWait("\\disk24\tech_svcs-shared\DST\Tools\HomeDirBld\DE-HomeDirectoryBuilder.exe") Send ("(SHIFTDOWN)") Send ("(TAB)") Send ("(SHIFTUP)") Send ($id) EndIf MsgBox (0,"Prehire Complete" "Prehire has been added to system!") EndSwitch WEnd
Juvigy Posted October 31, 2018 Posted October 31, 2018 Does it work when you do that command manually? in powershell/cmd? C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command enable-mailbox -identity "&$id&" -database "&$data&"
water Posted October 31, 2018 Posted October 31, 2018 You could have a look at my AD UDF (Active Directory). The latest version has a function to create an Exchange mailbox using PowerShell (_AD_CreatemailboxPS). All dsquery|dsmod calls can as well be replaced using the AD UDF. 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 October 31, 2018 Author Posted October 31, 2018 Juvigy it works in Exchange Shell but not in Powershell so I am sure that is the problem. Water, this looks promising. But if I want to make some changes where instead of entering the UPI I just want to enter the exchange database, I am assuming I would need to make those changes in the AD.au3 file?
Mattw11486 Posted October 31, 2018 Author Posted October 31, 2018 Getting some errors I attached so I am sure I need to make some adjustments somewhere to get this working: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AD.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Auto Prehire Tool", 288, 438, 2295, 257) $EmployeeID = GUICtrlCreateInput("EmployeeID", 64, 104, 129, 21) $Radio1 = GUICtrlCreateRadio("Check for F drive Creation", 48, 216, 185, 17) $Database = GUICtrlCreateInput("Database", 32, 160, 209, 21) $Button1 = GUICtrlCreateButton("Create Employee", 72, 320, 163, 57) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $sUser=GUICTrlRead($EmployeeID) $sEMailServer=GUICTrlRead($Database) ; Open Connection to the Active Directory _AD_Open() If @error Then Exit MsgBox($MB_ICONERROR, "Encountered an Error", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended) ; Let the user confirm the data before creating the mailbox If MsgBox($MB_YESNOCANCEL, "Confirm Information", "Are you sure that you want to connect to" & @CRLF & " " & $sEMailServer & @CRLF & "and create a mailbox for user" & @CRLF & " " & $sUser) <> $IDYES Then Exit ; Create the mailbox Global $vResult = _AD_CreateMailboxPS($sUser, $sEMailServer) If @error > 0 Then If @error < 7 Then MsgBox($MB_ICONERROR, "Error!", "_AD_CreateMailboxPS returned @error = " & @error & ", @extended = " & @extended) Else _ArrayDisplay($vResult, "_AD_CreateMailboxPS returned @error = " & @error & ", @extended = " & @extended) EndIf Else _ArrayDisplay($vResult, "The Mailbox has been successfully created!") EndIf _AD_Close() $CMD = "dsquery user -samid "&$sUser&"| dsmod user -loscr SWA" RunWait(@ComSpec & " /c " & $CMD) if GUICtrlRead($Radio1) = 1 Then ;~ $CMD = "dsquery user -samid "&$id&"| dsmod user -hmdir \\sdcpflr002\"&$id&" -hmdrv F:" RunWait("\\disk24\tech_svcs-shared\DST\Tools\HomeDirBld\DE-HomeDirectoryBuilder.exe") EndIf EndSwitch WEnd
water Posted October 31, 2018 Posted October 31, 2018 It depends on the values you pass as parameters to _AD_CreateMailboxPS. Do you use the URI format as described in the example script: "http://YourExchangeServerNameGoesHere.CompanyName.com" 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 October 31, 2018 Author Posted October 31, 2018 So I am a noob at this so forgive me if I say something wrong. But instead of using the URI format we just place them in a database through exchange. For example, since the user already exists in AD, I will go to Exchange Management Console and create a new mailbox, provide the existing user's employee id then specify what database they are in based on their job role (they will either be placed in a MAPI database or OWA database). This will create the mailbox for the user but I also need to add a SIP account I think the exchange management shell command is going to be something like: Enable-Mailbox -Identity -Alias 'their employee id' -Database 'MAPI/OWA'
Mattw11486 Posted November 1, 2018 Author Posted November 1, 2018 (edited) So I think I have figured out a majority of this. The main problem I seem to be having is the connecting to the URI I get the following error: Edited November 1, 2018 by Mattw11486
water Posted November 1, 2018 Posted November 1, 2018 Seems you need to ask your IT for support. 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