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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Maries
Posts: 17
Last visit: Mon Feb 09, 2015 12:00 pm

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

Post by Maries »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Mon Feb 09, 2015 12:00 pm

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

Post by Maries »

Ok
Last edited by Maries on Tue Feb 03, 2015 10:19 pm, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Mon Feb 09, 2015 12:00 pm

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

Post by Maries »

Ok
Last edited by Maries on Tue Feb 03, 2015 10:18 pm, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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

https://technet.microsoft.com/en-us/lib ... 92852.aspx
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Mon Feb 09, 2015 12:00 pm

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

Post by Maries »

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 10:20 pm, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
This topic is 9 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked