5
votes

I'm a global admin for our 365 environment and I'm having an issue with the Set-UserPhoto command in powershell. If I run it for my own username, it works just fine but if I run it using anyone else's username, it errors. Is there some kind of access I need to give myself to make this work? I'm a domain admin and global administrator in 365 so I should be able to do anything.

Connected through PowerShell 3.0 using the following:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxyMethod=RPS -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session

Command I'm running:

Set-UserPhoto –Identity username -PictureData ([System.IO.File]::ReadAllBytes("C:\userpics\username.jpg"))

Works fine for my username, for any other username I get this:

Error on proxy command 'Set-UserPhoto -Identity:'username' -PictureData: Tons of numbers here that scrolls for quite a while -Confirm:$False' to server BN3PR0201MB1027.namprd02.prod.outlook.com: Server version 15.01.0534.0000, Proxy method RPS: The WinRM client cannot process the request. The connection string should be of the form [://][:][/] where transport is one of "http" or "https". Transport, port and suffix are optional. The host may be a hostname or an IP address. For IPv6 addresses, enclose the address in brackets - e.g. "http://[1::2]:80/wsman". Change the connection string and try the request again. . + CategoryInfo : NotSpecified: (:) [Set-UserPhoto], CmdletProxyException + FullyQualifiedErrorId : Microsoft.Exchange.Configuration.CmdletProxyException,Microsoft.Exchange.Management.Reci pientTasks.SetUserPhoto + PSComputerName : outlook.office365.com

3
Is this the only command for Office 365 that you get the error for?Persistent13
Haven't gotten any other error at all from any other command that I've had to do.Cole
Long shot but, how many groups is the account you used apart of? This would include AD in you have on-prem sync enabled. support.microsoft.com/en-us/kb/3067263 may be the cause and I figure O365 support would have to assist you further if it is.Persistent13
@Persistent13 That's probably it I bet, my domain admin account is a member of a ridiculous number of groups. I'll do some testing and post back to confirm if that was it or not. Thanks!Cole
Made a new user which is only a member of Domain Users, gave this user global admin in 365 and tried the command again and got the same result. Seems the number of groups was not the cause.Cole

3 Answers

3
votes

just ran into the exact same problem.

the solution was to run Microsoft Azure Active Directory Module for Windows PowerShell 'as administrator' (Elevated)

as seen here https://www.blackforce.co.uk/2016/09/23/set-userphoto-error-proxy-command

0
votes

If you are in hybrid mode and thumbnailPhoto property is synched, you can only change the user photo in your local Active Directory and not in Office 365 Exchange PowerShell session.
If you are not in hybrid mode you can try this sample code instead:

Set-UserPhoto "username" -PictureData ([Byte[]] $(Get-Content -Path "C:\userpics\username.jpg" -Encoding Byte -ReadCount 0)) -Confirm:$false
0
votes

I had the same issue, and solved it from another post (I don't remember which one).

In the connection string:

$LiveCred = Get-Credential

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

Import-PSSession $Session