Powershell Script to Split data in a cell and print them in different rows

44 views Asked by At

I am trying to achieve the result in image two below:

enter image description here

Image2:

enter image description here

I tried using a PowerShell foreach loop to loop through the users; but it is printing only the last user in the list.

1

There are 1 answers

0
user2940413 On

I used foreach to loop through the users, which allowed me to display them in separate rows, but my code takes a while to complete.

A snippet of the code is shown below.

$tmpobject = $NULL
$Assignments = @()
$GroupMembers = Get-AzADGroupMember -ObjectId $groupID |
  Select-Object DisplayName -ErrorAction SilentlyContinue 
#$groupMemberName = $GroupMembers.DisplayName

foreach ($GroupMember in $GroupMembers) {
  $tmpobject = [ordered]@{
    "Subscription Name"           = $subscriptionName
    "Scope Name"                  = $scopeName
    "Users"                       = $GroupMember.DisplayName
    "Resource Name"               = $resourceName
    "Resource Type"               = $resourceType
    "Display Name"                = $displayName
  }

  $Assignments += New-Object PSObject -Property $tmpobject
}