I am having some issues with a script. I am trying to pull some info out of AD in to a CSV file. Now i am able to pull the SamAccountName and the firstname and lastname of the Secretary and i am trying to do the same with the seeAlso attribute. Secretary and seeAlso are both DN attributes.
I am just getting nothing in the CSV file for seeAlso
Secretary and seeAlso seem to be special properties generated by the Quest AD cmdlets. Since most of us will not have access to these cmdlets it might be hard to find someone able to help you further.
You are setting the output to '' (empty string) if there are errors. How about setting them to something helpful in case of an error to be able to troubleshoot your code?
What do you get when you query one particular users seeAlso attribute?
And please ā¦ do not format code as quotes. Instead format it as code.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
In fact. I have just noticed that accounts where there is only a single entry in the seeAlso field are returning a first name and last name back to me in a CSV. Where there are two or more i am seeing nothing in the CSV. I am a little unsure what would need to be done to my original code to over come that?
I thought that post had been removed. I have had to refresh my browser a few times to see it again.
using -join ', ' didnt change anything. In the code above i get blanks in the CSV not System.Object[] which if i was at least getting that it would be something.
Ok, so this code gets me closer. So now when i run this i am getting two or more CN= in the Secretary field. But what i need here is just the LastName , FirstName of the accounts listed.
Iād expect this from your try catch block if there is an error ā¦
Thatās why I asked what you get back when you query one of these user account where you get these blanks.
So you either query the AD for each of the accounts and extract FirstName and LastName or you use string acrobatics to slice the output into the pieces you want.
BTW: Is there a particular readson why youāre using the Quest AD cmdlets? AFAIK ended their support already and they are actually not necessary anmore since the MSFT AD cmdlets provide sufficient functionality.
And you will probably find easier / better / more help on the default MSFT AD cmdlets.
You do not query for the first and last name you query for the account and there included you have the properties for first and last name.
Do you really get only the CN returned? ā¦ or is it the DistinguishedName? Iād recommend to try to get one of the unique names from the AD like DistinguishedName, sAMAccountName or UserPrincipalName. With this you could create a hashtable in advance and use this as lookup table inside your loop. That would reduce the stress you put on your AD.
Does āblah blahā mean āFirstName LastNameā only or does it mean ā*FirstName LastName,OU=Users,OU=City,DC=Contoso,DC=comā or something like this? The latter one is the DistinguishedName and should be prefered.
So you have everything you need. Again - as I said earlier - Iād query all potentially needed accounts in advance, save them to a hashtable and use this as lookuptable in a nested loop inside your loop.
So this is what i have knocked up. Its not mega pretty but for now i can live with that as i just need something working.
So i am grabbing all the DN from the Secretary field and from there i am grabbing the SamAccountName. From that i am able to grab the value from an attribute called firstname-lastname-display
Now if i write-host $ADsecretaryName then as an example i am returned Steve and Jane
Now the CSV seems to be only adding to the report āsection Secretaryā = $ADsecretaryName the very last name returned.
Any ideas? I need to have everything in the same CSV column field? Its not -Append to the CSV file itself, Just need all data in the Secretary CSV Column
If youād format your code properly you might see your failures yourself. What do you use as your IDE? Iād recommend using VSCode since it gives you a lot of help and hints.
But again: This way you put a lot of stress to your AD since you query it for each individual user and again for each individual secretary.
Iād query it only once in advance reading all relevant users and attributes and work with this data.