VMware Cloud Community
COS
Expert
Expert
Jump to solution

Values in variable list have trailing spaces - Ho to get rid of trailing spaces?

I populate my variable with a list of my templates....

$MyTemplates = get-template | Select-Object Name | ft -HideTableHeaders

I get a list of....

server2019_gui         

server2019_cor         

server2016_gui         

server2016_cor         

server2016 domaincont_remotesite         

server2016 domaincont_homesite         

Problem is there are a bunch of spaces at the end of each line.

How do you get rid of those spaces? I tried $MyTemplates.Trim() but no luck and I get errors or I am using that totally wrong........lol

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are using the Format-Table cmdlet, which is intended to format text going to the console, to populate a variable.
You should do this as follows

$MyTemplates = Get-Template | Select-Object -ExpandProperty Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You are using the Format-Table cmdlet, which is intended to format text going to the console, to populate a variable.
You should do this as follows

$MyTemplates = Get-Template | Select-Object -ExpandProperty Name


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos