I am now approaching the world of scripting in PowerShell and I need your help with a little script that might be trivial.
I'm trying to make a script with the following requests:
- Take via input various Mailbox / Shared Mailbox (in which the user is present)
- Remove the user auto-mount (in this case it is found as "[email protected]".
The script is this for the moment:
#populate the list with the Mailbox / Shared to be removed
$mailboxList = Get-Content -Path "C:\Temp\Mailboxlist.txt"
$ConfirmPreference = 'none'
foreach($Mailbox in $mailboxlist)
{
#perform the operation on the current $ mailbox
Get-mailboxpermission -identity $Mailbox -User "[email protected]" | ? {$.AccessRights -like "FullAccess" -and $.IsInherited -eq $false } | remove-mailboxpermission -confirm:$false
Add-MailboxPermission -Identity $Mailbox -User "[email protected]" -AccessRights:FullAccess -AutoMapping $false
}
I would like to know if this command could work correctly, also because every time I try it comes out this:
PS C:\Temp> C:\Temp\RemoveAutoMapping.ps1
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: (Microsoft.Excha...sentationObject:PSObject) [Remove-MailboxPermission], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Exchange.Management.RecipientTasks.RemoveMailboxPermission
+ PSComputerName : outlook.office365.com
You might be able to try this out:
Since the functions is using the same parameters you can remove, and readd it in the same function fairly easily. Obviously change Access Rights and/or other permissions such as SendAs, as needed.