How to list the profile photo size in Active Directory.

I have tried to list all the profile photo size in Active Directory. However, I could not make it. I also used the script "GetThumbnailPhotoSize.ps1" to run it but got error.

PS C:\> .\GetThumbnailPhotoSize.ps1

Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\GetThumbnailPhotoSize.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r

 Collecting user accounts...
Exception calling "FindAll" with "0" argument(s): "A referral was returned from the server.
At C:\GetThumbnailPhotoSize.ps1:35 char:27
+ $Users = $Searcher.findall <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

 Evaluating the thumbnailPhoto size for  users...
You cannot call a method on a null-valued expression.
At C:\GetThumbnailPhotoSize.ps1:50 char:25
+         $UserDn = $UserDn.Trim <<<< ("GC")
    + CategoryInfo          : InvalidOperation: (Trim:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At C:\GetThumbnailPhotoSize.ps1:53 char:27
+         $Upn = $User.Properties[ <<<< "userPrincipalName"].Value
    + CategoryInfo          : InvalidOperation: (userPrincipalName:String) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\GetThumbnailPhotoSize.ps1:54 char:33
+         $ByteArray = $User.Properties[ <<<< "thumbnailPhoto"].Value
    + CategoryInfo          : InvalidOperation: (thumbnailPhoto:String) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

        Users with large photos:        0
        Users with OK photos:           0
        Users with no photo:            1


The script is in the website below:
Could you please advise me ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you changed the script parameters? The following would need to be changed for your environment
$Root = [ADSI]'GC://dc=contoso,dc=com'

If your Active Directory domain was BigCompany.local the line would look like
$Root = [ADSI]'GC://dc=bigcompany,dc=local'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dongocdungAuthor Commented:
It worked. thanks,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.