Where Do I Get the Powershell Cmdlet Remove-UserPhoto

Viewed 10348

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 Answers

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.

Related