none
PowerShell - Changing Names in Active Directory RRS feed

  • Question

  • I am trying to run a script to see how many user accounts that we have that Display Name and Full Name are First Name Last Name. The purpose is just to show the amount of changes that we have to make. I already have the script to change these names.

    So far this is what I have and it just pulls every account even if the format is lastname, firstname.

     get-aduser -filter * -properties samaccountname,  name, displayname| 
    Where {($_.displayname -notcontains ","-or $_.name -notcontains ","  )} | select samaccountname, name,
    displayname | Sort-object name| export-csv c:\scripts\wrongnames.csv -notype

    • Moved by Bill_Stewart Friday, August 4, 2017 9:42 PM This is not "scripts on demand"
    Thursday, June 29, 2017 5:08 PM

All replies

  • This could be an inspiration for you:
    Get-ADUser -Filter * -Properties DisplayName | 
        Select-Object -Property SamAccountName,DisplayName,Name,GivenName,SurName |
            ForEach-Object {
                $FirstLastPattern = $_.GivenName + '.*' + $_.SurName
                [PSCustomObject]@{
                    SamAccountName = $_.SamAccountName
                    DisplayName = $_.DisplayName 
                    GivenName = $_.GivenName
                    SurName = $_.SurName
                    Name = $_.Name
                    Pattern = $FirstLastPattern
                    DisplayFirstLast = If($_.DisplayName -match [REGEX]::Escape($FirstLastPattern)){$true}Else{$false}
                    NameFirstLast = If($_.Name -match [REGEX]::Escape($FirstLastPattern)){$true}Else{$false}
                }
            } | Format-Table
    ... and please format your code as code when you post it here. Thanks

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, June 29, 2017 6:15 PM
  • .... and you didn't even say "thanks"  ....  :-/

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Monday, July 3, 2017 10:51 AM