Adding Entries To AcceptMessagesOnlyFrom
I ran following command, $users = Get-Content E:\Folder\Filename.txt Then, $OldUsers = (Get-DistributionGroup -identity DGNAME).AcceptMessagesOnlyFrom ---> it contains no users.So $OldUsers is basically empty. $users+= $OldUsers OR $OldUsers+=$users Set-DistributionGroup -identity DGNAME -AcceptMessagesOnlyFrom $OldUsers Users in filename.txt which are non-existing in the Exchange fails to add and alongwith users which are present. How can i make the cmdlet to skip the non-existing users and continue to add existing users in $OldUsers. I tried to use -EA SilentlyContinue OR Inquire. But it fails. I have thousands of users in the text file. any suggestions.
September 5th, 2011 8:35pm

you can check for each user from filename.txt if it has mailbox with 'if' statementRegards, Konrad Sagala, MCT, MCSE+M, MCITP: Exchange 2007/2010
Free Windows Admin Tool Kit Click here and download it now
September 5th, 2011 9:29pm

If there's that many users in the txt file, it might be faster to start with the list of mail users, and filter that on the ones that appear in txt file.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
September 5th, 2011 10:09pm

On Mon, 5 Sep 2011 17:35:01 +0000, SYLVESTERCLARK wrote: > > >I ran following command, > >$users = Get-Content E:\Folder\Filename.txt > >Then, $OldUsers = (Get-DistributionGroup -identity DGNAME).AcceptMessagesOnlyFrom ---> it contains no users.So $OldUsers is basically empty. > >$users+= $OldUsers OR > > $OldUsers+=$users > >Set-DistributionGroup -identity DGNAME -AcceptMessagesOnlyFrom $OldUsers > >Users in filename.txt which are non-existing in the Exchange fails to add and alongwith users which are present. How can i make the cmdlet to skip the non-existing users and continue to add existing users in $OldUsers. I tried to use -EA SilentlyContinue OR Inquire. But it fails. I have thousands of users in the text file. > >any suggestions. Before you start modifying the $OldObject, be sure it's something the understands the "+=" operator! If ($OldObject -isnot [array]) { if ($OldObject -isnot [object]) # it's $null { $OldObject = @() # an empty list } else { $OldObject = @($OldObject) # list with one object } } After that, you can use the "get-recipient" cmdlet to validate the contents of each address in the file. $users = @() Get-Content E:\Folder\Filename.txt | foreach { if ($u = get-recipient $_) { $users += $u } } Now you should be able to "$OldObject += $users". --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
September 6th, 2011 12:27am

Hi SYLVESTERCLARK, You can use this to do that: $users=Get-Content E:\Folder\Filename.txt Foreach($user in $users) { $value=get-recipient –identity $user $OldUsers = (Get-DistributionGroup -identity DGNAME).AcceptMessagesOnlyFrom If($value –ne $null) { $OldUsers+=$user Set-DistributionGroup –identity DGNAME –AcceptMessagesOnlyFrom $OldUsers } } Thanks Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com
September 6th, 2011 5:54am

On Tue, 6 Sep 2011 02:54:05 +0000, Evan Liu wrote: [ snip ] >$OldUsers = (Get-DistributionGroup -identity DGNAME).AcceptMessagesOnlyFrom >If($value ?ne $null) >{ > $OldUsers+=$user Does that work if the membership has exactly one member? ;-) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2011 5:05am

Yes, it worked in my lab (Exchange 2010 SP1). Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com
September 7th, 2011 5:37am

Hi SYLVESTERCLARK, Any updates on this issue? Thanks, Evan Liu TechNet Subscriber Support in forum If you have any feedback on our support, please contact tngfb@microsoft.com
Free Windows Admin Tool Kit Click here and download it now
September 13th, 2011 4:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics