I’m working with Exchange and getting hung up on the fact that if I assign a variable to a list that is either read from the pipeline, or imported with import-csv, the list is one of objects, not strings, and when I wish to then loop through the list with an operation, the operation is expecting a string, not an object.
My use-case here is that I have a list of UserPrincipalNames (i.e. email accounts), that I wish to remove from a list of distribution groups.
So, for example:
$abcdepeeps = Get-Content abcdepeeps.txt $abcdegroups = Get-DistributionGroup -domain abcde.com foreach ($peep in $abcdepeeps) { foreach($group in $abcdegroups) { remove-distributiongroupmember -identity $group -member $peep } }
This brings up an error that says the distribution group list are objects, not strings.
Cannot process argument transformation on parameter ‘Identity’. Cannot convert the
“ABCDE.Logistics” value of type “Deserialized.Microsoft.PowerShell.Commands.MatchInfo” to
type “Microsoft.Exchange.Configuration.Tasks.DistributionGroupIdParameter”.
- CategoryInfo : InvalidData: (
[Remove-DistributionGroupMember], ParameterBind
in…mationException - FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-DistributionGroupMem
ber - PSComputerName : outlook.office365.com
My workaround is to write out the object to a text file and then reimport, but that is such a pain…I keep thinking there should be a function that would do the conversion?