I'm writing a script to audit the disk partition types in my company's virtual environment using PowerCLI. I've got this code so far:
$report = @()
$VMs = (Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'}
foreach ($VM in $VMs){
$vmName = $VM.Name
$output = Invoke-VMScript -ScriptText @'
Get-Disk |
select @{ l="ComputerName"; e={ $env:COMPUTERNAME } },
Number,
@{ name='Size'; expr={[int]($_.Size/1GB)} },
PartitionStyle
'@ -VM $vmName -GuestUser $Username -GuestPassword $Password
$output.ScriptOutput #printing each for testing
$report += $output.ScriptOutput
}
$report | FT -AutoSize
This will produce an output that looks like this:
ComputerName | Number | Size | PartitionStyle |
---|---|---|---|
VMNAME1 | 0 | 100 | MBR |
VMNAME1 | 1 | 20 | GPT |
VMNAME1 | 2 | 20 | MBR |
ComputerName | Number | Size | PartitionStyle |
---|---|---|---|
VMNAME2 | 0 | 100 | MBR |
VMNAME2 | 1 | 20 | GPT |
The issue I'm facing is that the output report has the column headers repeated for each VM. How can I fix this to only have the column headers displayed one time, like this:
ComputerName | Number | Size | PartitionStyle |
---|---|---|---|
VMNAME1 | 0 | 100 | MBR |
VMNAME1 | 1 | 20 | GPT |
VMNAME1 | 2 | 20 | MBR |
VMNAME2 | 0 | 100 | MBR |
VMNAME2 | 1 | 20 | GPT |
Any ideas for how I can do this? I'm new to powershell so I'm not sure what to do.