早上好!
我有一个快速的问题。 我将如何删除与特定用户关联的邮件联系人? 这是我曾经试过的:
Get-Mailbox 'jsmith' | select ForwardingAddress | Remove-MailContact
这会引发一个命令pipe道错误:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. + CategoryInfo : InvalidArgument: (@{ForwardingAdd...ding/J Smith}:PSObject) [Remove-MailContact], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Remove-MailContact
然后我试了一下,以防万一:
Get-Mailbox 'jsmith' | select ForwardingAddress | Remove-MailContact $_
并收到了这个:
Cannot bind argument to parameter 'Identity' because it is null. + CategoryInfo : InvalidData: (:) [Remove-MailContact], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-MailContact
但是,如果我运行这个:
Get-Mailbox 'jsmith' | select ForwardingAddress
我给了这个回应:
ForwardingAddress ----------------- ObfuscatedDomain.com/E-mail Forwarding/J Smith
名字已经改变,以保护无辜。
很明显,我用Exchange PowerShell并不是很棒,但是我正在学习哈哈。 我假设这个问题是因为从select的ForwardingAddress返回的数据不是一个标识符Remove-MailContact将接受。 但是,Get-Mailbox只有两个“转发”属性。
首先, ForwardingAddress属性不必对应于一个Mail Contact。 (我有几个列出其他邮箱和不less名单通讯组)。 请记住,当我们继续。
问题是你使用SELECT动词,以及它如何返回属性的一部分,而不是完整的对象。 尝试: Remove-MailContact $(Get-Mailbox "jsmith").ForwardingAddress
这是获取转发地址的对象。 另一种select(如果你不介意的话)将是:
$mailbox = Get-Mailbox "jsmith" $forward = $mailbox.ForwardingAddress Remove-MailContact $forward
请记住,所有这些都假设ForwardingAddress引用了一个MailContacttypes的对象,这是不能保证的(它可以是任何types的Direcotry.ADObjectId)
我相信你正在寻找Disable-MailUser <username> ,这将禁用帐户的电子邮件帐户部分,但保持AD用户帐户不变。
如果您要删除在Active Directory中没有User帐户的联系人的电子邮件属性,那么您正在查找Disable-MailContact <username> 。