Adding a Function and grouping data output

Welcome Forums General PowerShell Q&A Adding a Function and grouping data output

Viewing 1 reply thread
  • Author
    Posts
    • #198239
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      SysOps Forum Team

      Just to let you know I am kind for new (newbie) to PowerShell scripting. I have put together this script below to retrieve data from Active Directory (Name, OperatingSystem, IPV4, Last Login, & calculate and output Days Since Last Logon).

      That being said, it does exactly what I initially built it to do. Since I originally wrote this we have grown a bit and I need to make a couple of changes that I am not sure how to complete.

      > First I would like to make the “Retrieve AD Data” into a function so that I apply requests for multiple locations (i.e. San Diego, San Antonio, Charlotte)

      > Second I would like to group each location by

      – (i.e. San Diego’s – SD02, SD03, SD04)

      – (i.e. San Antonio’s – SA01, SA03, SA04, SA05)

      – (i.e. Charlotte’s – CL01, CL02)

       

      So the output that I would like is

      1. One report that outputs each: (preferred)
      • Grouped by: <u>San Diego, San Antonio, & Charlotte</u>
      • Grouped by: <u>Server Groupings</u>
      • Sorted by: <u>Days Since Last Logon</u>

      OR

      1. Separate reports for each (may be easier)
      • Grouped by: <u>Server Groupings</u>
      • Sorted by: <u>Days Since Last Logon</u>

       

      I did make an attempt to user Group-Object (probably incorrectly) and while it did group them, it ended up adding a lot of extraneous information to the right of the “Name” column (pushing it all the way to the right) and excluding all previous columns to the right that was previously there (Shown below).

      <u>PowerShell output:</u>

       

      <u>Attempt to use Group-Object:</u>

      I apricate any assistance that can be provided

    • #198275
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Before you can do grouping, you need to parse out what you want to Group a bit, take something like this:

      This will give you output like this:

      Then you can do grouping like so:

Viewing 1 reply thread
  • The topic ‘Adding a Function and grouping data output’ is closed to new replies.