4
votes

I cannot find this anywhere on the web and am in need of an answer so I can remove all user photos from profiles in our Azure AD account. Microsoft so kindly documents how to use Get-UserPhoto and Remove-UserPhoto, but does not explain how to actually get the Cmdlet.

I event went to their docs page for connecting to Azure Active Directory in Powershell, but that was no help either. It allowed me to download the AzureAD module (thinking that I needed it to run those Cmdlets), but no luck. Anyone tell me how in the world do I get the module that contains those commands?

Updated Question: We only using Office 365. We do not have any on-site Exchange server, so how am I supposed to execute Exchange PowerShell scripts without it? How would any administrator do this? It's hard for me to believe that I'm the only idiot out there that needs to remove photos from the profiles in Office 365 and would like to do this in an automated fashion.

The other problem I'm seeing is that when I browse to our user list, the photos don't appear in the User list in Azure. But if I go to random O365 apps (like Teams for instance), the profile picture appears.

3
Apparently that's an Exchange (Online) cmdlet available in Exchange 2013 and 2016, so I'd expect it to be available in the Exchange PowerShell console or after loading the Exchange PowerShell snapin in a regular PowerShell console (Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn).Ansgar Wiechers
@ansgar wiechers : adding the snapin is -as far as I know - unsupported (some Exchange CMDlets also don't work if you do that). For Exchange (and Exchange Online) the supported way is creating a session and importing it with Import-PSSession.bluuf
So how exactly do I run the Get-UserPhoto or Remove-UserPhoto?clockwiseq
You can use remote powershell. techyv.com/questions/…Jacob Colvin
Unfortunately, after running the command to start a new session with Exchange, I still get the error that Get-UserPhoto is not recognized as the name of a cmdlet, function, script file, or operable program.clockwiseq

3 Answers

2
votes

You need to connect to your remote Exchange Online session:

$credential = Get-Credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession

As soon as you do that, you will import the module that contains Remove-UserPhoto cmdlet and will be able to do what you want.

0
votes

Get a Photo:

$user = Get-ADUser "UserName" -Properties thumbnailPhoto
$user.thumbnailPhoto | Set-Content "C:\folder\photo.jpg" -Encoding byte

Set a Photo:

$photo = [byte[]](Get-Content "C:\folder\photo.jpg" -Encoding byte)
Set-ADUser "UserName" -Replace @{thumbnailPhoto=$photo}

Remove a Photo:

Set-ADUser "UserName" -Clear thumbnailphoto
0
votes

Run PowerShell ISE as administrator. Make sure the account you use has administrative rights.

Paste into top and hit play button:

$credential = Get-Credential
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection Import-PSSession $exchangeSession

When prompted, sign into your Office account with the full email address: rsmith@xyz.org:

PS C:>Set-UserPhoto -Identity "rsmith" -PictureData ([System.IO.File]::ReadAllBytes("C:\rsmith.jpg")) -Confirm:$false

or:

PS C:>Set-UserPhoto -Identity "Ryan L. Smith" -PictureData ([System.IO.File]::ReadAllBytes("C:\rsmith.jpg")) -Confirm:$false

Make sure that this account is an Office admin account. Note that the -Confirm:$false is optional.