locked
Script needed to separate enabled users from disabled RRS feed

  • Question

  • Hi guys,

    I have written a script to extract a list of memberships of certain AD groups, with the member's SamAccountName's outputted into a variable ($users).

    What I would like to do now is put a line together in order to filter out all of the users within this list that are disabled. Maybe even create two separate variables from this ($enabledUsers and $disabledUsers).

    I have tried the following, but the 'Get-ADUser' part then grabs all users within AD, not just the list from the $users variable.

    $enabledUsers = $users | % {Get-ADUser -Filter {(Enabled -eq "True")}}

    Any help would be gratefully appreciated.

    Cheers 

     

    • Moved by Bill_Stewart Monday, April 30, 2018 9:13 PM Unanswerable drive-by question
    Monday, February 19, 2018 1:17 PM

All replies

  • What script?  You posted something that you copied.  It returns all enabled users.

    Try starting by learning basic PowerShell and AD.  Once you have basic knowledge you will be able to understand what you are copying.

    Also learn to use the CmdLet help.

    Note that, in PowerShell, true and false are always $true and $false and NOT "True" or "False". This is one of the fist things you will learn when you study PowerShell.

    Please carefully review the following links to set your expectation of technical forums.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests


    \_(ツ)_/

    Monday, February 19, 2018 1:31 PM
  • It's a simple question jrv, no need for the attitude.

    This part gets a list of the groups required:

    $groups = Get-ADGroup -Filter {name -like "START OF GROUP NAME*"} -Properties Description | Where-Object {$_.Description -like "*PART OF REQUIRED DESCRIPTION*"}

    This part gets the list of users from the groups above:

    $users = ($groups | % {Get-ADGroupMember -Identity $_ }).SamAccountName

    Now I would like to create two more variables from the $users variable ($enabledUsers and $disabledUsers).

    If you haven't got that know-how jrv, please don't say anything and let an expert respond.

    Cheers


    • Proposed as answer by jrv Monday, February 19, 2018 1:52 PM
    • Unproposed as answer by jrv Monday, February 19, 2018 1:52 PM
    Monday, February 19, 2018 1:47 PM
  • Not the original question and I am only noting that thi forum is not here to custom fix scripts you have found on the Internet.  All of your questions show you have not learned even the most basic elements of PowerShell.  You need to do that.

    First you can pipe the CmdLets.
    Second you should not mist filter types as it is less efficient and more prone to error.
    Third you will have to filter the results on the "Enabled" property.


    \_(ツ)_/

    Monday, February 19, 2018 1:56 PM
  • Copied from the Internet? What?

    Look, all three lines have been written from scratch. The third line (below) isn't giving me the required results - hence the question.

    $enabledUsers = $users | % {Get-ADUser -Filter {(Enabled -eq "True")}}

    I'm not getting into an argument about this. How silly. I'll use another forum.

    Monday, February 19, 2018 2:05 PM
  • I told you you cannot use "True" for a Boolean.  Also the code posted makes no sense.

    What is "$users".

    If you want "Disabled" then why are you trying to use "True".

    You need to know AD as well as PS.  If you are doing that from scratch it is a very bad guess caused by lack of any basic knowledge of PowerShell.

    To get disabled users:

    Get-AdUser -Filter {Enabled -eq $false}

    You cannot use a ForEach-Object to drive a CmdLet without understanding how that works.

    Get-AdGroup mygroupname | Get-AdGroupMember


    \_(ツ)_/

    Monday, February 19, 2018 2:12 PM
  • Exactly the same question. Different forum.

    Answer almost immediately.

    Cheers jrv

    Feel free to mark as answered for your points.

    Monday, February 19, 2018 2:31 PM
  • Which means you have learned nothing.

    Why is it that you new guys don't want to learn anything about the technology you are using?  It make no sense.


    \_(ツ)_/

    Monday, February 19, 2018 2:33 PM