我在哪里获取PowerShell命令Remove-UserPhoto的Cmdlet?

4
我在网上找不到答案,需要知道如何删除我们Azure AD帐户中的所有用户照片。微软友善地记录了如何使用Get-UserPhotoRemove-UserPhoto,但没有解释如何获取Cmdlet。
我甚至去了他们的文档页面连接PowerShell到Azure Active Directory,但也没有帮助。它允许我下载AzureAD模块(认为我需要它来运行这些Cmdlet),但没有成功。有人能告诉我如何获得包含这些命令的模块吗?

更新的问题: 我们只使用Office 365。我们没有任何本地Exchange服务器,那么我该如何执行Exchange PowerShell脚本呢?任何管理员应该如何处理这个问题?很难相信我是唯一一个需要在Office 365中自动删除配置文件中的照片的傻瓜。

我看到的另一个问题是,当我浏览用户列表时,在Azure中的用户列表中不会显示照片。但如果我进入随机的O365应用程序(例如Teams),则会显示配置文件图片。


显然,这是Exchange 2013和2016中可用的Exchange(在线)cmdlet,因此我希望它可以在Exchange PowerShell控制台中使用,或者在常规PowerShell控制台中加载Exchange PowerShell snapin(Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn)后使用。 - Ansgar Wiechers
@ansgar wiechers:据我所知,添加Snapin是不受支持的(如果这样做,某些Exchange CMDlet也无法正常工作)。对于Exchange(和Exchange Online),支持的方法是创建会话并使用Import-PSSession导入。 - bluuf
那么我应该如何运行 Get-UserPhoto 或 Remove-UserPhoto 呢? - clockwiseq
1
你可以使用远程 PowerShell。http://www.techyv.com/questions/how-to-connect-to-exchange-online-with-microsoft/ - Jacob Colvin
很遗憾,在运行启动与Exchange的新会话命令后,我仍然收到错误提示:Get-UserPhoto不被识别为命令、函数、脚本文件或可操作程序的名称。 - clockwiseq
3个回答

2

您需要连接到远程Exchange Online会话:

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

一旦您这样做了,您将导入包含 Remove-UserPhoto cmdlet的模块,并能够完成您想要的操作。


1

以管理员身份运行PowerShell ISE。确保您使用的帐户具有管理权限。

将内容粘贴到顶部并点击播放按钮:

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

当提示时,请使用完整的电子邮件地址rsmith@xyz.org登录您的Office帐户:
PS C:>Set-UserPhoto -Identity "rsmith" -PictureData ([System.IO.File]::ReadAllBytes("C:\rsmith.jpg")) -Confirm:$false

或者:

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

请确保此帐户是Office管理员帐户。 请注意,-Confirm:$false 是可选的。


为了充分利用Set-UserPhoto cmdlet的功能,您必须通过在ConnectionUri参数后附加?proxyMethod=RPS来更改连接URI。我只看到答案的一个更正。 - blayderunner123

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

设置照片:

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

删除照片:
Set-ADUser "UserName" -Clear thumbnailphoto

我被指派删除所有照片。我看到你有一个设置照片的例子。你有没有想过如何在不使用Remove-UserPhoto cmdlet的情况下删除它们? - clockwiseq
@Keith 只需将 thumbnailPhoto 设置为 $null。 - Vesper

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接