简体   繁体   中英

Automated script to change user photos in Microsoft Exchange 2013 (powershell)

I have a simple script, that gets all users from Exchange, scans for their photos in folder (name.jpg), then updates the photo.

The porblem is - when it tries to change the photo for ANYONE except me - it generated a very big ERROR "Error from proxxy server Set-UserPhoto -Identity $someone -PictureData: LOTS OF NUMBERS -Change;$False" Error - Request entry too large. Here is part of the code with this script.

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -Credential $cred
[Array]$AllUsers = Get-MsolUser -All | Select-Object DisplayName
$i = 0
$p = 0
$e = 0
Add-Content $logPATH ("`Read Successful`n")
Add-Content $logPATH ("`rPhoto folder path: `n" + $PATH + "\PHOTOS\")
$photoPATH = $PATH + "\PHOTOS\"
foreach ($CurUser in $AllUsers) 
{
    $i++;
        $search = $CurUser.DisplayName + ".jpg"
        $curname = $CurUser.DisplayName
        $pathp = $photoPATH  + $search
        if (Test-Path ($pathp))
        {
            #'photo will be added'
            $p++
            $photo = ([Byte[]] $(Get-Content -Path $pathp -Encoding Byte -ReadCount 0))
            $curname
            Try
            {
                Set-UserPhoto  $curname -PictureData $photo #-Confirm:$False
            }
            Catch
            {
                Add-Content $ERRORPATH ($_  + "`n")
            }
            Add-Content $logPATH ("`rDone: Photo updated for user " + $CurUser.DisplayName + "`n")
        }
        else
        {
            $e++
            Add-Content $logPATH ("`rERROR: Cant find photo for user: " + $CurUser.DisplayName + "`n")
        }
}

Sorry for broken english.

EDIT: Here is the fill error text: Error proxxy server "Set-UserPhoto -PictureData: [Lots of NUMBERS, probably pic. data] -Identity: [name], -Confirm:$False" for server [our server].outlook.com: ServerVersion 15.00.0995, method PSWS

The remote server returned an error: (413) Request Entity Too Large... + CategoryInfo : NotSpecified: (:) [Set-UserPhoto], CmdletProxyException + FullyQualifiedErrorId : Microsoft.Exchange.Configuration.CmdletProxyException,Microsoft.Exchange.Management.Reci pientTasks.SetUserPhoto

My thoughts - entry is too large because it contais full code for photo. But somehow it works for ME.

This is a known bug. I opened a case with MS recently. They are working on it. You can upload up to a 10K photo for your own account, but are limited to around 1K for other users, regardless of your rights. I am a global admin for example. YOu are stuck with AD sync for this process at the moment

Add this to the url in the Session Line. ?proxymethod=rps So it looks like this.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ ?proxymethod=rps -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $Session

I got this from Microsoft support Patrick Reynolds (Allyis Inc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM