Adding Members to a Distribution Group with a CSV - Passing a $null variable
Live@EDU Environment - Exchange 2010
Afternoon,
I am creating a large amount of distribution groups, some have members and some will only have the owner initially.
Is there any way to pass a $null imported value in this scenario so that the cmdlet completes successfully but does not have a value for the -Members attribute?
Import-Csv C:\PowerShell\resource-test.csv | foreach { New-DistributionGroup -Name $_.GroupName -Alias $_.GroupAlias -CopyOwnerToMember -ManagedBy $_.OwnerPrimarySMTP -Members $_.MembersPrimarySMTP.split(",") }
Couldn't find object "$null". Please make sure that it was spelled correctly or specify a different object.
+ CategoryInfo : NotSpecified: (0:Int32) [New-DistributionGroup], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : 3E963AFD,Microsoft.Exchange.Management.RecipientTasks.NewDistributionGroup
If I run it by itself, it completes without any issue.
New-DistributionGroup -Name "OCIS Test Resource" -Alias grp.OCIS.test_resource -CopyOwnerToMember -ManagedBy janestaff@uga.edu -Members $null
Thank you for your assistance. I apologize if this has been asked already but I was unable to find it.
Rachel
September 14th, 2010 9:19pm
You can try something like this (I haven't tested it):
$Members = $_.MembersPrimarySMTP.split(",")
If ($Members.length -eq 0) {$Members = $Null}
Import-Csv C:\PowerShell\resource-test.csv | foreach { New-DistributionGroup -Name $_.GroupName -Alias $_.GroupAlias -CopyOwnerToMember -ManagedBy $_.OwnerPrimarySMTP -Members $Members }
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2010 9:28pm
On Tue, 14 Sep 2010 18:19:21 +0000, Rachel Moorehead wrote:
>
>
>Live@EDU Environment - Exchange 2010
>
>
>
>Afternoon,
>
>I am creating a large amount of distribution groups, some have members and some will only have the owner initially.
>
>Is there any way to pass a $null imported value in this scenario so that the cmdlet completes successfully but does not have a value for the -Members attribute?
>
>Import-Csv C:\PowerShell\resource-test.csv | foreach { New-DistributionGroup -Name $_.GroupName -Alias $_.GroupAlias -CopyOwnerToMember -ManagedBy $_.OwnerPrimarySMTP -Members $_.MembersPrimarySMTP.split(",") }
Are you trying to use the method "split" on the value "$null"? IOW, is
the "MembersPrimarySMTP" an object or is it not?
It might be a better idea to only execute the split if the
"$_.MembersPrimarySMTP -is [object]".
Maybe something like this?
foreach {if ($_.MembersPrimarySMTP -is [object]){$m =
$_.MembersPrimarySMTP.split(",");new-distributionsgroup ... -Members
$m} else {new-distributiongroup ...}}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
September 14th, 2010 10:25pm