Support Forums

Help with VB Script - Get the Managers sAmAccountName?

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.
User avatar
Maries
Posts: 17
Joined: Wed Jan 21, 2015 10:23 am

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby Maries » Mon Feb 02, 2015 9:02 pm

Thx, that was helpful, I did figure that out. What I'm literally stuck at is where the code goes?

I can see what the command does that you provided, but in the script I posted, I must be putting the set mgr command in the wrong place, because the script errors out.

Does that command go at the top where the ad query is, and then when you pass the value, does that go where the recordset values are setup?
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Mon Feb 02, 2015 9:10 pm

Sorry - I can't see the error.

You have to sonsider that I do not have your database so I cannot possibly know what you are trying to do.

Is there some reason why you cannoot get the person who wrote thsii scritp to help you. A quick lookshows that it has a large number of problems and willnotlikelywork reliably.
User avatar
Maries
Posts: 17
Joined: Wed Jan 21, 2015 10:23 am

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby Maries » Tue Feb 03, 2015 1:28 pm

Ok
Last edited by Maries on Tue Feb 03, 2015 11:19 pm, edited 1 time in total.
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Tue Feb 03, 2015 2:06 pm

The script starts out with On Error Resume Next. This hides all errors and allows the script to appear to not be making mistakes. It is a wild card if it works.

You can just add the line I posted along with the rest of the lines. It may not work due to other issues with the script.

It is clear that you are not someone who written scripts so it is very hard to know what it is that you have tried and what you mean by saying it doesn't work.

I can show you the code that you would need to use. I can say place it anywhere in the loop. I cannot see what you are doing and, since all error processing is turned off, the failure are impossible to know.

You will have the same issues in PowerShell.
PowerShell Code
Double-click the code block to select all.
$managerdn=(Get-Aduser userid -properties manager),Manager
$managersamname=(Get-AdUser $managerDN ).SamAccountName
User avatar
Maries
Posts: 17
Joined: Wed Jan 21, 2015 10:23 am

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby Maries » Tue Feb 03, 2015 2:37 pm

Ok
Last edited by Maries on Tue Feb 03, 2015 11:18 pm, edited 1 time in total.
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Tue Feb 03, 2015 2:47 pm

Here is an older but still good article on error handing in VBScript.

https://technet.microsoft.com/en-us/library/ee692852.aspx
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Tue Feb 03, 2015 2:50 pm

maries wrote:I won't have the same issues as I understand at least the basics, if not more with PowerShell.

I know that it's frustrating helping me out with this issue, but I stated that I had "no experience with vbscripting", and that script was written many years ago with no comments, no documentation, and yes, I know it moves on after any error basically.

All I can say is that it works as the SQL Administrator has the job scheduled and the database is populated, it ran this morning actually and we verified it pulled in new users that were created yesterday.

I tried pasting the code you provided into the script, but from what I've read the get command has to run after it pulls the user info, so that's where I got lost trying to figure out where in the code it should go.

Powershell makes logical sense to me as the commands and the syntax where VB doesn't. I do appreciate your help though, thanks again. If you have any good PowerShell learning sites, book suggestions, training videos suggestions, or otherwise, please let me know. I don't think I'll try learning VB at this point as I don't think it's needed now with Powershell.


As I have noted many times. You can place the code anywhere inside of the loop and it will work assuming there is a manager defined. Are you sure that managers have been defined?

I have no idea what or how you are pasting this. You give almost no information and describe no errors. How can anyone technically understand your issues.

If you know PowerShell then you should know these things.

With no information on what you are doing I do not see how it is possible to help you.
User avatar
Maries
Posts: 17
Joined: Wed Jan 21, 2015 10:23 am

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby Maries » Tue Feb 03, 2015 3:31 pm

This is definitely a much bigger task than I expected. I've found other posts and it appears you can't pull the info I want like this.
Last edited by Maries on Tue Feb 03, 2015 11:20 pm, edited 1 time in total.
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Tue Feb 03, 2015 4:13 pm

I posted this line to show you how to do an assignment.

rs.Field("manager") = mgr.SamAccountName

I recommend contacting a consultantt to help you with this. I have answered your question as to how to get the SamAccountName of the manager, You already have proven that that works. I cannot spend time fixing all of the issues with your script. THis is not a free scripting service. It is a foru for technicians who write and maintain scripts.

I recomemnd learning VBScript r contacting a consultant who can help you.

As for the field set, if you look, you will see that it already has the "manager" specified.
User avatar
jvierra
Posts: 9723
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Help with VB Script - Get the Managers sAmAccountName?

Postby jvierra » Tue Feb 03, 2015 4:16 pm

Givenyou setup thiswouldgt the managers name assuming the errors do not hide why it cannot be done.

VBScript Code
Double-click the code block to select all.
'
SQLRecordset.Fields("manager") = GetObject("LDAP://" & adoRecordset.Fields("manager").Value).SamAccountName

Return to “VBScript”

Who is online

Users browsing this forum: No registered users and 2 guests