none
Formatting the output of the script RRS feed

  • Question

  • I have create a script that fetches the name of AD Object, however there are some user defined properties in the objects that requires some formatting initially I was simply loading the properties and the data was obtained in proper tabular structure.

    Get-ADGroup -Filter { 'objectClass' -eq 'grp' } -Properties Name, GUID | Select Name, GUID

    From the script above the data will be loaded in this format

    Name             GUID

    -------           --------

    Test              ABCD-1234-XXXX

    Test2            JKLM-4567-YYYY

    I have a function that I am using to count the days let say do operation on the group after some x days. So, the count of x is fetched through that function. Say CountX(). 

    So, my script is somewhat like.

    $ADGROUP = Get-ADGroup -Filter { 'objectClass' -eq 'grp' } -Properties Name, GUID | Select CountX(GUID) +" - "+ Name, GUID

    function CountX($ADGroup){

    #SomeOperations Counting the DueDate return $DueDate #Lets Say The Date is in the format "yyyy/MM/dd" }

    $ADGroup | Select-Object -Join (CountDueDate($ADGroup), Name), ObjectGUID // Concatenating Name & Date String()

    But the script is causing the error :  The term 'CountDate' is not recognized as the name of a cmdlet, function, script file, or operable program. I think I am not invoking my function properly. Any Suggestions?

    My Expected Output is Suppose to be:

    Name                                GUID

    -------                               --------

    2019/01/01 Test               ABCD-1234-XXXX

    2019/01/01 Test2             JKLM-4567-YYYY


    • Edited by Nikul Vyas Wednesday, July 17, 2019 8:08 PM
    Wednesday, July 17, 2019 8:08 PM

All replies

  • It's hard to help when you don't share your actual code but I think you should take a step back and start to learn the basics of Powershell.

    From what I can see in your code you could either use calculated properties for your Select-Object or a PSCustomObject in a Foreach-Object or a foreach statement.


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, July 17, 2019 10:14 PM
  • What operations are done inside CountX?, you may need to use hashtable in select object instead of calling a function. Something like:

    Get-ADGroup -Filter { 'objectClass' -eq 'grp' } -Properties Name, GUID | Select @{n="ColumnName"; e = {SOMEOPERATIONS}}, GUID

    Thursday, July 18, 2019 8:51 AM
  • What operations are done inside CountX?, you may need to use hashtable in select object instead of calling a function. Something like:

    Get-ADGroup -Filter { 'objectClass' -eq 'grp' } -Properties Name, GUID | Select @{n="ColumnName"; e = {SOMEOPERATIONS}}, GUID

    Get-AdGroup does not require a filter as it is already a filter.

    The original question doesn't really make much sense and the code even less.


    \_(ツ)_/

    Thursday, July 18, 2019 8:54 AM
    Moderator
  • Ah yes, as jrv stated, why are you filtering the groups again with 'grp'? Also the objectClass is 'group' I think.

    When you are using Get-ADGroup, only the groups are going to get fetched, there is no need to filter the same again.

    Thursday, July 18, 2019 9:08 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, July 31, 2019 7:33 AM
    Moderator