1
votes

I am attempting to put together an Exchange Online (Office 365) PowerShell script to bulk process mailboxes with the commandlet set-clutter in order to turn off the mailbox clutter feature. The following PowerShell command can be run for individual mailboxes:

set-clutter -identity "MailboxIdentityHere" -enable $false

I have a CSV file with the identities of each mailbox.

I am not a programmer and am a novice with scripting and realize I don't completely understand my issue.

I have been able to put together the following script:

$Identities = Import-csv "pathtofile\filename.csv"
foreach ($Identity in $Identities)  
{
set-clutter -identity $Identity -enable $false
}

However I get the following error repeated for each iteration of the mailboxes listed in the CSV file:

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "@{IDENTITY =ProjectMailbox1}" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert hashtable to an object of the following type: Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter. Hashtable-to-Object conversion is not supported in restricted language mode or a Data section." + CategoryInfo : InvalidData: (:) [Set-Clutter], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Clutter + PSComputerName : outlook.office365.com

Based off the error message I believe I unerstand that there is a mismatch in the data type between what is being passed from the CSV file to the variable and what the commandlet is expecting. I don't have enough knowledge to proceed further or remedy this.

Here is an example of how the CSV file looks:

ALIAS

ProjectMailbox1
ProjectMailbox2
ProjectMailbox3
ProjectMailbox4
etc...

2

2 Answers

2
votes

It always pays to sanity check the data you have in your variable. Piping it to Get-Member can give you some insight into the data you're using.

In this case, assuming the first line in you CSV is ALIAS, and you piped $Identities to Get-Member you'd see something along the lines of:

[2] PS C:\temp> $Identities | get-member


   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
ALIAS       NoteProperty string ALIAS=ProjectMailbox1

Notice there is an Alias property which contains the value ALIAS=ProjectMailbox1

This means when you're looping through all Identities, you're looping through ALIAS=ProjectMailbox1, ALIAS=ProjectMailbox2, ALIAS=ProjectMailbox3, rather than the data you're actually expecting.

To get the result you're expecting, you need to reference the property you're after, in your specific case (judging by the error message) it looks like you need to reference the Identity property:

set-clutter -identity $Identity.Identity -enable $false

Import-CSV attempts to create an object, it is expecting multiple columns in your CSV file to build out all the properties of your objects. For instance you may have FirstName, LastName, Alias, SamAccountName columns, and you'd be able to call either of those properties.

If you're only dealing with one 'column' of data, your better off just using a text file with one item per line (and no heading at the top). Then you can import the text file with Get-Content and iterate over it and you'll be dealing with simple strings as you'd expect rather than single property psobjects.

0
votes

If you're only dealing with one 'column' of data, your better off just using a text file with one item per line (and no heading at the top). Then you can import the text file with Get-Content and iterate over it and you'll be dealing with simple strings as you'd expect rather than single property psobjects.

I just wanted to point out that this is something to bear in mind. I just spent the past hour trying to figure out why I was no longer getting the PrimarySMTPAddress from my objects. All because I had decided to use Import-CSV over Get-Content.