Link to home
Start Free TrialLog in
Avatar of itsmevic
itsmevicFlag for United States of America

asked on

Excel 2010: Macro that pulls WMI Info

Hello Experts!

   I have a spreadsheet that contains NetBiosNames (Computer Names) in column A.  Row 1 is my Header Row:

           Column A                        Column B
1.     NetBiosName                     Username
2.   computername1                  johndoe1
3.   computername2                  johndoe2
4.   computername3                  johndoe3
5.   computername4                  johndoe4
6.   computername5                  johndoe5

I'd like a control button that I can click on, that will pull the username for each computer name entry in my spreadsheet if possible.  Any help with this macro is greatly appreciated.
Avatar of aikimark
aikimark
Flag of United States of America image

what do need to do with the data?
Avatar of itsmevic

ASKER

I use the data in a report at work.
This code will iterate the cells.
Dim rngData As Range
Dim rngUser As Range
Set rngData = ActiveSheet.Range(ActiveSheet.Range("B2"),ActiveSheet.Range("B2").End(xlDown)
For Each rngUser In rngData
   Debug.Print rngUser.Value
Next

Open in new window

Hi Aikmark,

    Does this code actually pull the WMI information from each machine and produce a username associated to each machine?
No.  This code iterates the cell data you described in your question.
Oh, okay, so it doesn't actually go out to get anything, it's just simply code that will populate "something" in the range of cells mentioned, correct?  It doesn't actually go out to WMI and pull the username based off the computername (NetBiosName)?
>>It doesn't actually go out...
That is not the question you asked, or at least that is not how I read it.

Perhaps you can rephrase the question.
it's in the Subj line and last paragraph.  ( :
Question rephrased:

Two columns in excel i.e.

Column A                                          Column B
NETBIOSNAME(computername)        Username


Headers take up row 1 so data would start populating on Row 2.

Need a macro that will go out and search WMI for the username of each NetBiosName(ComputerName) entered in column A and populate that username value in Column B.

Paste in computer names in Column A.  Hit the Get User control button and it goes out and pulls and populates the username in Column B for each computername in Column A.

Hopefully that helps clarify things.
SOLUTION
Avatar of Steve
Steve
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi there S. -  Will the code above pull the username from each computer populate the username in column B?
I think the code above will pull the names off a local computer.
If you run them, the imediate window in the VBA editor will have some information in it.
If the information you require is in either of the two outputs let us know and then we can use it to generate the VBA to get your dsired result.
At the moment I am "fishing" hoping one of the sets of WMI code will return the data you need.
Though I think that the actual WMI to obtain usernames from remote PC will require authentication. I am on the case, but this is not something that is done often, so am having to refresh memory as I go. Hopefully we can just keep casting out and hopefully we will catch something, then can write the code to populate your list and land our fish :)
ATB,
Steve.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rob, you're a friggin' coding BEAST!....LOL!  Great to hear from you again sir! Hope you are well my friend!
LOL!  I'm doing alright thanks.  I'm finding less time for EE right now, but I hope to be back in full swing soon.

Rob.
That worked perfectly! Thank you everyone!
No problem.  Thanks for giving The_Barman an assist.  I forgot to mention that I swiped the second code block from his post.

Rob.
Both of you guys have always offered superb solutions and have taught me so much along the way.  Thank you!