Add function & ability to group in PowerShell script

Share
Viewing 2 reply threads
  • Author
    Posts
    • #1554523
      M Fix
      Participant
      Member Points: 81
      Rank: Level 1

      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

      A. One report that outputs each: (preferred)

      – Grouped by: San Diego, San Antonio, & Charlotte
      – Grouped by: Server Groupings
      – Sorted by: Days Since Last Logon

      OR

      B. Separate reports for each (may be easier)
      – Grouped by: Server Groupings
      – Sorted by: Days Since Last Logon

      Attempt to Resolve
      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).

      Current Script

      Attempt to use Group-Object:

      0
    • #1554525
      M Fix
      Participant
      Member Points: 81
      Rank: Level 1

      I appreciate any assistance you all can give.

      0
    • #1554555
      Michael Pietroforte
      Keymaster
      Post count: 1893
      Member Points: 24,844
      Author of the year 2018
      Rank: Level 4

      Functions are important in any programming language. Without functions you won’t get far with your scripting efforts. I suggest you first read this and then give it a try. If you then run into specific problems, you can ask here in the forum.

      As to Group-Object, it would be helpful, if you post the command you used.

      0
Viewing 2 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account