Copy multiple output to clipboard

I have a script to create (multiple) accounts.

At the end of the script I collect the username and the adgroups that the user is added as a member.
This information wil be exported to the clipboard to paste in the original request to create htis account.

When I create more than 1 account it collects al the accounts, while I would like to collect the information per account name. Since every accouint is requested in a seperate request.

Mayby you have a good way to realize this…?

#import the Data
$Import = import-csv 'P:\Users\PieterB\Scripts\CSV\New-GMSA Account.csv' -Delimiter ";"

#output to Topdesk
 
#create a string with all groups including the line breaks

$GroupList = $($Import.Adgroup).GetEnumerator() | Out-String
$PrincipalTD = $($import.Principal).GetEnumerator() | Out-String

$output = @()
$output += write-output "GMSA Account aangemaakt:`n $($Import.gmsa)`n"
$output += "PrincipalsAllowedToRetrieveManagedPassword :`n$($Import.principal)"
$output += "member of:`n$($GroupList)"

$output |set-clipboard

my csv looks like:

GMSA Domain Description Principal Adgroup
GMSAAcc0103 Domain0323 just a line for GSMA0103 w1022o0101,w1022o0102 Group A,Group B
GMSAAcc0104 Domain0323 just a line for GSMA0104 w1022o0101,w1022o0102 Group A,Group c
GMSAAcc0105 Domain0323 just a line for GSMA0105 w1022o0101,w1022o0102 Group D,Group B
GMSAAcc0106 Domain0323 just a line for GSMA0106 w1022t0132,w1022t0133 Group A,Group B
GMSAAcc0107 Domain0323 just a line for GSMA0107 w1022t0132,w1022t0134 Group A,Group c
GMSAAcc0108 Domain0323 just a line for GSMA0108 w1022t0132,w1022t0135 Group D,Group B

The output now looks like this: (example)

GMSA Account :
GMSAAcc0103 GMSAAcc0104 GMSAAcc0105 GMSAAcc0106 GMSAAcc010

PrincipalsAllowedToRetrieveManagedPassword :
w1022o0101,w1022o0102 w1022o0101,w1022o0102 w1022o0101

en toegevoegd aan:
Group A,Group B
Group A,Group c
Group D,Group B
Group A,Group B
Group A,Group c
Group D,Group B

Where I would like the output per GSMA Account.
GMSAAcc0103 with Principal w1022o0101,w1022o0102 is created .
And added to :
Group A,Group B
Group A,Group c

Hopefully it makes sense .
Thanks in advance for the hints/answers

PowerShell is made for/great in dealing with structured data and outputting them in a concise way to be able to process them further.

There is no built in cmdlet to transform those concise structured data into human friendly readable prosa. So you may use the structured data you collected and transform them with a loop to individual “reports” containing all the desired information and outputting them AS STRINGS. Now you can collect these strings again in one big chunk and output them to the clipboard.

1 Like