none
powershell script to get users from AD and compare with the file from yesterday RRS feed

  • General discussion

  • Hello,

    i'm doing one script to get users from Active Directory group and list in a csv file, the information needed is email, first name, last name, whenchanged and whencreated. This part i already have  the script:

    $dte = [datetime]"9/6/2017"
    Write-Host $dte
     
    Get-ADGroup "my_ad_group" | `
        Get-ADGroupMember -Recursive | `
        Get-ADUser -Properties * | `
        Select-Object @{Label = "ACTION";Expression = {if (($_.WhenChanged -gt $_.WhenCreated)  ) {'UPDATE'} Else {'ADD'}}},
        @{Label = "Email";Expression = {$_.Mail}},
        @{Label = "FirstName";Expression = {$_.GivenName}},
        @{Label = "LastName";Expression = {$_.Surname}},
        @{Label = "WhenChanged";Expression = {$_.WhenChanged}},
        @{Label = "WhenCreated";Expression = {$_.WhenCreated}},
        @{Label = "UserGroups";Expression = {"41796934"}}  | Where {($_.WhenChanged -gt $dte) -or ($_.WhenCreated -gt $dte)} | `
        Export-CSV -Path "C:\folder\file.csv" -NoTypeInformation
         $dte = [datetime]"1/1/2017"

    this part works good but the part with the " UPDATE" "ADD" doesnt work, i need to check if the account is disable in AD to mark it to REMOVE, if the account was not in the last file ADD, if the account was in the last file UPDATE. i tried a couple of solutions but nothing work.

    can someone give me some advice on this? 

    Thank you and sorry for my english :)

    • Changed type Bill_Stewart Wednesday, February 14, 2018 7:28 PM
    • Moved by Bill_Stewart Wednesday, February 14, 2018 7:28 PM This is not "here's my spec, someone design code for me to to it" forum
    Thursday, January 4, 2018 11:20 AM

All replies

  • It is very hard to understand what you are asking.  Your code just reports on what it finds.

    To check and account for disabled use the "enabled" property.


    \_(ツ)_/

    Thursday, January 4, 2018 11:46 AM
  • hi,

    let me show one example maybe it's easier to explain.

    ACTION Email FirstName LastName WhenChanged WhenCreated
    UPDATE  example1@email.com test  1 01/01/2018 18:43 05/03/2013 12:50
    ADD example2@email.com                                test 2 25/12/2017 02:13 05/03/2013 17:49
    REMOVE  example3@email.com test 3 26/12/2017 14:13 05/03/2013 17:50

    REMOVE means that the user is disable in active directory, the ADD means that the user was not in the CSV file from yesterday. UPDATE means that the user was in the file from yesterday. i have script running every day and every day it generates a csv file and overwrite the file from the day before. i hope it's more clear now. Thank you for your help and input on this.

    Thursday, January 4, 2018 1:46 PM
  • Are you asking for us to design a solution for you?  That is not the purpose of this forum.

    Try asking the person who wrote the script you are suing for help modifying it or take the time to learn PowerShell and AD.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests


    \_(ツ)_/

    Thursday, January 4, 2018 3:37 PM
  • i'm not asking that, only if there is anyone with some scripts similar with what i need that i can take ideas or something. i'm not a scripting guy but i'm trying to solve this and i'm stuck. 
    Thursday, January 4, 2018 3:43 PM
  • i'm not asking that, only if there is anyone with some scripts similar with what i need that i can take ideas or something. i'm not a scripting guy but i'm trying to solve this and i'm stuck. 

    That is why I posted the links.  Look in the Gallery for pre-written scripts. This forum is not a place to ask for free scripts or for solutions it is for questions about scripting for scripts you have written.

    \_(ツ)_/

    Thursday, January 4, 2018 4:07 PM
  • You are essentially providing a specification and asking for someone to redesign/rewrite your script (or write a new one) that meets your specification. That's outside the scope of this forum.

    -- Bill Stewart [Bill_Stewart]

    Thursday, January 4, 2018 4:19 PM