Check UserID for Differences

What prompted me to look for this solution was an error we received while trying to run –

Get-CSUser TBOLTON

I received this error –

Management object not found for identity "tbolton".
+ CategoryInfo : InvalidData: (tbolton:UserIdParameter) [Get-CsUser], ManagementException
+ FullyQualifiedErrorId : Identity,Microsoft.Rtc.Management.AD.Cmdlets.GetOcsUserCmdlet
+ PSComputerName : BigDog.ad

The issue turned out to be the Alias Setting on the General Page in Exchange.  For what ever reason the entry there was BOLTONTIM

Today I found what Get-CSUser was keying off of in AD, it was keying off of, “MailNickName”.

# Used To Check for any differences in a UserID

# Example - PS C:\>Check-UserID TBOLTON

Function Check-UserID {
param(
[parameter(Mandatory = $true)]
[String] $UID)
$User=(Get-ADUser $UID -Properties *)
$UserSAM=$User.SamAccountName
$UserName=$User.Name
$UserCN=$User.CN
$UserNickName=$User.MailNickName
# Report if there are differences
if (($UserSAM -eq $UserName) -and ($UserName -eq $UserNickName))
{
"`r`n"
Write-Host -foregroundcolor Green "The UserId"  $UID  "WAS a match"
"`r`n"
Write-Host -foregroundcolor Green "SAM Account:  " $UserSAM
Write-Host -foregroundcolor Green "User Name: -- " $UserName
Write-Host -foregroundcolor Green "CN: --------- " $UserCN
Write-Host -foregroundcolor Green "Mail ALias: - " $UserNickName
"`r`n"
} else {
"`r`n"
     Write-Host -foregroundcolor Red "The UserId"  $UID  "did NOT match"
"`r`n"
Write-Host -foregroundcolor Red "SAM Account:  " $UserSAM
Write-Host -foregroundcolor Red "User Name: -- " $UserName
Write-Host -foregroundcolor Red "CN: --------- " $UserCN
Write-Host -foregroundcolor Red "Mail ALias: - " $UserNickName
"`r`n"
    }
}

——————————————————————————–
In this example my account is intentionally set up wrong while the first account is set up correctly.
 CheckUserID

One Response to Check UserID for Differences

  1. Tim Bolton says:

    Thanks Claus!

    I had forgotten about the Here-String @” “@ I thought it was only for Email Body within the script. I did not realize that you could use it for “any” text.

    Another option

    Function Check-UserID {
    param(
    [parameter(Mandatory = $true)]
    [String] $UID)

    if (-not (Get-Module -Name ActiveDirectory)) {
    Import-Module ActiveDirectory
    }

    $User=(Get-ADUser $UID -Properties *)
    $UserSAM=$User.SamAccountName
    $UserName=$User.Name
    $UserCN=$User.CN
    $UserNickName=$User.MailNickName

    # Report if there are differences
    if (($UserSAM -eq $Usersam) -and ($UserName -eq $UserNickName)) {

    $text = @”

    The UserId $UID WAS a match

    SAM Account: $UserSAM
    User Name: — $UserName
    CN: ——— $UserCN
    Mail ALias: – $UserNickName
    “@
    Write-host -ForegroundColor Green $text
    }

    else {
    $text = @”
    The UserId $UID did NOT match

    SAM Account: $UserSAM
    User Name: — $UserName
    CN: ——— $UserCN
    Mail ALias: – $UserNickName
    “@
    Write-host -ForegroundColor Red $text
    }
    }

    Check-UserID ctn

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: