Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Export to excel
    • Sign In

    • State Not Answered
    • Replies 4 replies
    • Subscribers 65 subscribers
    • Views 995 views
    • Users 0 members are here

    Export to excel

    Luc Poulin
    Offline Luc Poulin over 3 years ago

    Hello

    In my quest to undertsand PWShell

    i have wrote this code

    $Groups = Get-PWGroupNames

    foreach ($Group in $Groups) {

    $Group

    Get-PWMembers -Type Group -Name $Group

    }

    Now i'm not sure how to output this in Excel so I have two colums, one being the group name, the other the username.

    • Sign in to reply
    • Cancel
    Parents
    • Brian Flaherty
      0 Offline Brian Flaherty Thu, Mar 5 2020 6:17 AM

      Give this a try

      # Create datatable and add desired columns.
      $dt = New-Object Data.Datatable ('Users')
      $dt.Columns.Add("GroupName")
      $dt.Columns.Add("MemberType")
      $dt.Columns.Add("UserName")
      
      $Groups = Get-PWGroupNames
      
      foreach ($Group in $Groups) {
      
          $pwGroupMembers = Get-PWMembers -Type Group -Name $Group
      
          # Loop through all group members and add to the datatable.
          foreach($pwGroupMember in $pwGroupMembers) { 
              $dr = $dt.NewRow()
              
              $dr.GroupName = $Group
              $dr.MemberType = $pwGroupMember.MemberType
              $dr.UserName = $pwGroupMember.MemberName
          
              $dt.Rows.Add($dr)
          }
      }
      
      # Export to Excel file.
      New-XLSXWorkbook -InputTables $dt -OutputFileName 'd:\temp\export\GroupMembership.xlsx'

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Luc Poulin
      0 Offline Luc Poulin Thu, Mar 5 2020 2:10 PM in reply to Brian Flaherty

      Thank you Brian

      This make me ask one question, based on when I was helping  programmer but note doing any coding. Do we have documentation that allow us, newbie coders, to know the expected return string for an argument or trigger ( not sure what is the correct term to be use)

      Some kind of correlation table

      Example:

      For user inside a group below are the support argument/trigger

       .MemberType = xxxx

      .MemberName = xxxx

      .MemberDomain = xxxx

      .MemberDescription = xxxxxx

      And each could be associate in an infographic to the graphical interface ( when the result is expose in the user interface)

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Reply
    • Luc Poulin
      0 Offline Luc Poulin Thu, Mar 5 2020 2:10 PM in reply to Brian Flaherty

      Thank you Brian

      This make me ask one question, based on when I was helping  programmer but note doing any coding. Do we have documentation that allow us, newbie coders, to know the expected return string for an argument or trigger ( not sure what is the correct term to be use)

      Some kind of correlation table

      Example:

      For user inside a group below are the support argument/trigger

       .MemberType = xxxx

      .MemberName = xxxx

      .MemberDomain = xxxx

      .MemberDescription = xxxxxx

      And each could be associate in an infographic to the graphical interface ( when the result is expose in the user interface)

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    Children
    No Data

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies