I'm writing this script and when the output occurs, there is too much space between the -Name and the -Value of the PSObject, here is what it looks like:
Total Templates : 60
Total VMs : 499 "Too much space"
Total ESXi Hosts : 36
Here is what I want, the -Name, a space and then the -Value. The colon is in there as part of the object (Why is the colon automatically there anyway, and can it be changed to something else? Maybe a dash -)
Total Templates: 60
Total VMs: 499
Total ESXi Hosts: 36
The script I'm workign on is larger, I just decided to play around with the formattting, so I made something short so I can have fast results, and not wait for all the data to process.
Here is the script that produced this
Hello, DZ1-
There are a couple of things causing that extra space after the name of the property:
So, even if you weren't using Format-List, the extra characters in the property name cause that extra space. The use of Format-List is also the reason for the colons.
You could better control the output by just returning an object from the function, and then creating the desired string. A quick update to the function to make it return just an object with the names/values populated:
Function MyTest2 {
New-Object -Type PSObject -Property @{
"Total Templates" = (Get-Template | Measure-Object).Count
"Total VMs" = (Get-VM | Measure-Object).Count
"Total ESXi Hosts" = (Get-VMHost | Measure-Object).Count
} ## end new-object
} ## end fn
Then, you could make any kind of string you want from the output. To output a few lines with the names and values separated by a dash, as you suggested, you could do something like:
MyTest2 | %{$oTmp = $_; Get-Member -Input $oTmp -MemberType NoteProperty} | %{"$($_.Name)- $($oTmp.$($_.Name))"}
Sample output:
Total ESXi Hosts- 171
Total Templates- 12
Total VMs- 3901
How does that do for you?
Sorry, I forgot to mention, I was playing around with the "`t", I was going to try and make a tab for each line to even it out, I had the fl in there because the actual script was not looking right (the example is just something I used to play with), so I used format-list because I'm having different information in different sections. I should have removed the tab, but I was trying different things, and I forgot to take it out. I will try what you suggested though...thank you.