none
Removing all group members from all Distribution groups listed in a txt file RRS feed

  • Question

  • Hey All,



    Hoping I would be able to get some assistance <g class="gr_ gr_17 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="17" id="17">on</g> a script <g class="gr_ gr_24 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="24" id="24">writing</g>.

    I'm trying to run an <g class="gr_ gr_35 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="35" id="35">autoscript</g> where it removes all users from all distribution groups listed within a text file, however, <g class="gr_ gr_41 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="41" id="41">i</g> keep getting this error:

    Import-Module ActiveDirectory

    $users = Get-ADUser -Filter * -Properties * | Where-Object {$_.DistinguishedName -like "*OU=Users,OU=Australia,OU=XXX,DC=xxx,DC=local"}

    $ListDLs = Get-Content C:\Scripts\ListDL.txt

    #clear all members in our DLs
    Foreach ($dl in $ListDLs)
    {
            $ListDLALL = Get-ADGroupMember -Identity $dl
            Remove-ADGroupMember -Identity $dl -Members $ListDLALL -Confirm:$false
            $ListDLALL = ""
    }

    However, when the script is run, I get this error:

    <g class="gr_ gr_61 gr-alert gr_gramm gr_hide gr_inline_cards gr_run_anim Style multiReplace replaceWithoutSep replaceWithoutSep" data-gr-id="61" id="61">Remove-</g><g class="gr_ gr_61 gr-alert gr_gramm gr_hide gr_inline_cards gr_disable_anim_appear Style multiReplace replaceWithoutSep replaceWithoutSep" data-gr-id="61" id="61"><g class="gr_ gr_62 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="62" id="62">ADGroupMember</g></g><g class="gr_ gr_61 gr-alert gr_gramm gr_hide gr_inline_cards gr_disable_anim_appear Style multiReplace replaceWithoutSep replaceWithoutSep" data-gr-id="61" id="61"> :</g> Cannot validate argument on parameter 'Members'. The argument is null or empty. Provide an argument that is not null or empty, and then try <g class="gr_ gr_70 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" data-gr-id="70" id="70">the </g>
    <g class="gr_ gr_70 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Style multiReplace" data-gr-id="70" id="70">command</g> again.
    At line:4 char:53
    +         Remove-ADGroupMember -Identity $dl -Members $ListDLALL -Confirm:$false
    +                                                     ~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Remove-ADGroupMember], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.RemoveADGroupMember


    If someone could help, would be greatly appreciative... <g class="gr_ gr_88 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="88" id="88">i</g> have been sitting on this for weeks with no result... 



    Regards,

    J
    • Edited by Jon Enright Wednesday, January 31, 2018 3:17 AM removed weird characters
    • Moved by Bill_Stewart Monday, March 12, 2018 9:08 PM Unreadable post filled with garbage pseudo-HTML strings
    Wednesday, January 31, 2018 3:12 AM

All replies

  • Please fix your post.  It is completely unreadable.  You cannot post HTML formatted text in this forum or it will be unreadable.


    \_(ツ)_/

    Wednesday, January 31, 2018 3:19 AM
  • its weird as it was all copied from notepad - i was just trying to delete and now wont allow me :-/

    Instead i submitted another question - which has put it in properly - but cant remove this one...

    Wednesday, January 31, 2018 3:29 AM
  • Just click the edit button and edit it.  DO NOT USE notepad++ as it does not work unless you know how to configure it.

    Some broken third party browser also do not work correctly. Use IE or Edge.


    \_(ツ)_/

    Wednesday, January 31, 2018 3:32 AM