itsmevic
asked on
VB Script: Active Directory
Hi Experts!
I'm curious if you guys have or know of a script that will search Active Directory user accounts for the following criteria:
Summary of Actions
Script needs to look for blank display names in active directory and if the display name is blank it needs to look for the CN name. The Display needs to be made the same as the CN name. This is only for accounts with a blank display name....
Steps:
1.) Scans and looks for any Blank Display Names in Active Directory.
2.) For the accounts the script detects that have a Blank Display Name, it will then populate change to those accounts to match what the CN name is.
3.) Finally, a results file of what was changed in .CSV format if possible?
Any help with this, is GREATLY APPRECIATED! Awarding MAX points!
Thanks again in advance!
I'm curious if you guys have or know of a script that will search Active Directory user accounts for the following criteria:
Summary of Actions
Script needs to look for blank display names in active directory and if the display name is blank it needs to look for the CN name. The Display needs to be made the same as the CN name. This is only for accounts with a blank display name....
Steps:
1.) Scans and looks for any Blank Display Names in Active Directory.
2.) For the accounts the script detects that have a Blank Display Name, it will then populate change to those accounts to match what the CN name is.
3.) Finally, a results file of what was changed in .CSV format if possible?
Any help with this, is GREATLY APPRECIATED! Awarding MAX points!
Thanks again in advance!
As for needing to change the display name to equal the actual name, you can use a modifed version of this script (asumming that these usernames are in one OU)
http://support.microsoft.com/kb/300427
I haven't tested it out, but it should be modified to something like this: (the last part of the script)
If you need something different, let us know...
http://support.microsoft.com/kb/300427
I haven't tested it out, but it should be modified to something like this: (the last part of the script)
If you need something different, let us know...
usr.put "displayName", usr.SamAccountName
usr.setinfo
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dammit... 2 minutes too slow ;)
Chris
Just like the other author said in a previous post
"The Chris-Dent is everywhere!!" :)
"The Chris-Dent is everywhere!!" :)
ASKER
Hey there ThinkPaper! Thanks for the great suggestions and I will definetely give the Microsoft script a shot and see what happens. For the modification where exactly would I need to embed this modification at? Also, this script does not appear to produce a results file i.e. .CSV file that I can use for reporting purposes.
Summary/Recap of request:
Scan AD for User Accounts that have Blank Display Names, FOR every Blank Display name found THEN populate the Display name with the CN name of that account. Produce results file in .csv format of all changes that were made.
Summary/Recap of request:
Scan AD for User Accounts that have Blank Display Names, FOR every Blank Display name found THEN populate the Display name with the CN name of that account. Produce results file in .csv format of all changes that were made.
'rem chgdisplay3.vbs - Changes the display names of all users in a given OU to the
'rem format of Lastname, Firstname Middle using the current displayName field and breaking this into 'seperate strings.
'rem Usage = cscript chgdisplay.vbs "OU=My Ou, DC=My Domain, DC=com"
'rem OU must be enclosed in quotes if it contains spaces in the name
Dim strTargetOU
ParseCommandLine()
wscript.echo strTargetOU
wscript.echo
wscript.echo "Changing Display names of users in " & strTargetOU
Set oTargetOU = GetObject("LDAP://" & strTargetOU)
oTargetOU.Filter = Array("user")
For each usr in oTargetOU
if instr(usr.SamAccountName, "$") = 0 then
if instr(usr.displayName, ",") = 0 then
vTempName = usr.get("displayName")
astrWords = split(vTempName)
CountWords = UBound(astrWords) - LBound(astrWords) +1
if CountWords = 2 then
vFirst = astrWords(0)
vLast = astrWords(1)
vFullname = vLast + ", " + vFirst
usr.put "Sn", vLast
usr.put "GivenName", vFirst
end if
if CountWords = 3 then
vFirst = astrWords(0)
vMiddle = astrWords(1)
vLast = astrWords(2)
vFullname = vLast + ", " + vFirst + " " + vMiddle
usr.put "Sn", vLast
usr.put "GivenName", vFirst
usr.put "middleName", vMiddle
end if
usr.put "displayName", vFullName
usr.setinfo
wscript.echo vFullName
end if
end if
Next
Sub ParseCommandLine()
Dim vArgs
set vArgs = WScript.Arguments
if vArgs.Count <> 1 then
DisplayUsage()
Else
strTargetOU = vArgs(0)
End if
End Sub
Sub DisplayUsage()
WScript.Echo
WScript.Echo "Usage: cscript.exe " & WScript.ScriptName & " <Target OU to change users display names in>"
WScript.Echo "Example: cscript " & WScript.ScriptName & " " & chr(34) & "OU=MyOU,DC=MyDomain,DC=com" & chr(34)
WScript.Quit(0)
End Sub
ASKER
WHATS UP CHRIS!!! long time man! Thanks for your input, you've helped me a ton in the past man!
ASKER
Thanks Ken and Chris, I'll give your suggestions a shot too!
It's probably only been a long time since I've been avoiding VbScript questions, you need to ask more PowerShell questions :)
Chris
Chris
There is one bit missing out of mine, need to update my code library here (home). It has no Page Size defined, so it'll cap out at 1000 users. Ken's has Page Size, I only recommend you steal my LDAP filter and drop the If statement about display name.
And just in case I can convince you... PowerShell version :-D
Get-QADUser -LdapFilter "(!(displayName=*))" | ForEach-Object { Set-QADUser $_.DN -DisplayName $_.Name } | Export-Csv "out.csv"
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh...my....god.....I didn't refresh for AGES! How embarassing.....
ASKER
Damn! All the heavy hitters are here....NICE!
LOL! You can try mine for fun, or you can ignore it....when I opened this question this morning, there were no posts.....I had a coffee, wrote the script, and by the time I hit submit, it got busy! LOL! Will I ever learn......
Nice to see it's not just me Rob.
~bp
~bp
Chris says: PS you can do this in one line of PowerShell ;)
And kill all the fun?! :)
And kill all the fun?! :)
ASKER
I tried to spread the points accordingly. All the suggestions were extremely helpful in helping me obtain what I was needing to accomplish. They just don't give you enough points to work with.... Thanks again for EVERYONE's input. I'm very APPRECIATIVE!
Unless there is some other requirement, there really is no need to do a script for this, unless you really really want to.