Powershell Array output in HTML

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 5 years, 11 months ago.

  • Author
    Posts
  • #5801

    by lhornyak at 2013-04-12 07:15:31

    I am working on a script that will return all groups and members of the groups from a site location into html format. When the report runs, I get the data
    @{Member Name=User1} @{Member Description=Loss Control Rep} @{GroupType=Security}
    @{Member Name=User2} @{Member Description=Loss Control Specialist} @{GroupType=Security}
    @{Member Name=User3} @{Member Description=Loss Control Specialist} @{GroupType=Security} etc .returned in the webspage. I tried using the .split command but it is not working exactly the way I would like. How can I format this output to look better?

    Add-Content $report "

    "
    $MName=$GroupInfo|Select 'Member Name'
    $MDes=$GroupInfo|Select 'Member Description'
    $MGroup=$GroupInfo|Select 'GroupType'
    Add-Content $report "

    $MName

    "
    Add-Content $report "

    $MDes

    "
    Add-Content $report "

    $MGroup

    "
    #Add-Content $report "

    $Member.Description

    "
    Add-Content $report "

    "

    Thanks in advance.

    by happysysadm at 2013-04-12 08:05:45

    Hi,

    I don't know the content of your $groupinfo, but if it is an array, try the following code:

    [code2=powershell]# preparing report name and location
    $reportname = 'report' + ("{0:ddMMyyyy-hhmmSS}" -f (get-date)) + '.html'
    $reportpath = Join-Path -path 'c:\yourreportfolder' -ChildPath $reportname
    # preparing table using html head
    # (this piece is not mine but I have often re-used it, I don't remember where I found it))
    $head = "

    "
    # piping $groupinfo into convert to html then on disk in one line
    $groupinfo|
    select 'Member name','Member description','GroupType' |
    Sort-Object 'Member name' |
    ConvertTo-Html -Head $head -Body "

    Members and groups

    "|
    Out-File -FilePath $reportpath[/code2]

    Check the syntax (specifically the properties names) and tell me if this is what you were after.
    Regards
    Carlo

    by lhornyak at 2013-04-12 12:43:25

    I have a lot of nested loops and I will be pulling in a lot of data from different OUs. When I use the convertto-html it does not have the blank rows between each of the nested groups. Here is my code (much of it borrowed and adapted). Is there a way to add blank rows when you use it with the convertto-html method?


    $GroupInfo = '' | Select 'Group Name','Group Description','Member Name','Member Description','GroupType'

    ######################################################################
    #REPORT HTML CODE#
    ######################################################################

    $report="Userreports1.htm"
    Clear-Content $report

    Add-Content $report ""
    Add-Content $report ""
    Add-Content $report ""
    Add-Content $report 'User Reports $s'
    add-content $report '

    "
    Add-Content $report ""
    Add-Content $report ""
    add-content $report "

    "
    add-content $report "

    "
    add-content $report "

    "
    add-content $report "

    "
    add-content $report "

    "
    add-content $report "User Group Report $Site"
    add-content $report "

    "
    add-content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    #######################################################################################

    $root = "test.com/locations"
    $GroupArray= get-qadobject -sizelimit 0 -searchroot $root -type group

    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "

    $AllGroups = @()

    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "

    foreach ($Location in $GroupArray){

    $MyGroups = Get-QADGroup $Location -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,Member,GroupType | select Name,Description,Member,GroupType

    ########################################################################

    add-content $report "

    "

    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    ########################################################################

    foreach($Group in $MyGroups){

    $GroupInfo.'Group Name' = $Group.Name
    $GroupInfo.'Group Description' = $Group.Description

    foreach($Member in $Group.Member){

    $User = Get-QADUser $Member -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,GroupType| select Name,Description,GroupType
    if (!$User) {$User = Get-QADgroup $Member -DontUseDefaultIncludedProperties -IncludedProperties Name,Description,GroupType | select Name,Description,GroupType
    }

    $GroupInfo.'Member Name' = $User.Name
    $GroupInfo.'Member Description' = $User.Description
    $GroupInfo.'GroupType' = $Group.GroupType
    $GroupInfo | select 'Group Name','Group Description','Member Name','Member Description','GroupType'
    $AllGroups += $GroupInfo | Select 'Group Name','Group Description','Member Name','Member Description','GroupType'

    ##################################################################################
    Add-Content $report "

    "
    $MName=$GroupInfo|Select 'Member Name'
    $MDes=$GroupInfo|Select 'Member Description'
    $MGroup=$GroupInfo|Select 'GroupType'
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-Content $report "

    "
    Add-content $report ""
    Add-Content $report "

    "
    }
    }
    }

    $AllGroups

    Invoke-item "userreports1.htm"

    Name Description Group Type
    $OU
    $Location
    $MName $MDes $MGroup

You must be logged in to reply to this topic.