I am trying to gather the following information about a VM's hard drive:
- Host Name
- VM Name
- Location of the VM Drive (on the host)
- Size of the VM Drive (on the host)
While my property names may not be the most conventional, I was developing this script overtime and wasn't too concerned with it. I have now run into a wall that I am unable to overcome. I get to the end of the script and have everything I want in the $FinalResults variable. The $FinalResults.<Property I want info for> shows me what I want but I am unable to export this in a way that will allow me to read it via a file or even out-gridview. Any help is greatly appreciated!
$Hosts=read-host'What are the name of the host you would like to check (Comma separated
for multiple, no spaces.)?'
$Hosts=$Hosts.Split(",")
$Results1= @()
foreach ($Hin$Hosts)
{
$Results1+=Get-VM–ComputerName $H | Get-VMHardDiskDrive |
Select-Object-Property @{n='Host';e={$_.ComputerName}}, VMName, Path, VMID |
Sort-Object-Property VMName
}
$Locations= @()
foreach ($Hin$Hosts)
{
$Locations+=Get-VM-ComputerName$H | Get-VMHardDiskDrive | Select-Object ComputerName,`
Path,VMName
}
$Results3= @()
foreach ($Locationin$Locations)
{
$FIle=$location.Path.ToString()
$Script="Get-ChildItem '$File'"
$Server=$Location.ComputerName
$Scriptblock=$ExecutionContext.InvokeCommand.NewScriptBlock("$Script")
$Results3+=Invoke-Command-ComputerName$Location.ComputerName-ScriptBlock$Scriptblock
| Select @{n='Computer';e={$_.PSComputerName}},Name,@{n='Size';e={$_.Length/ 1gb -as [int]}},`
@{n='Location';e={$File}}
}
$properties= @{
Host=$Locations.ComputerName;
'VMName'=$Locations.VMName;
'Size'=$Results3.Size;
'Location'=$Results3.Location
}
$FinalResults=New-Object–TypeName PSObject –Prop $properties
$FinalResults.Host,$FinalResults.Location,$FinalResults.Size,$FinalResults.VMName |
ConvertTo-Html-Title'VM Disk Stats' | Out-File$home\Desktop\test.html
for multiple, no spaces.)?'
$Hosts=$Hosts.Split(",")
$Results1= @()
foreach ($Hin$Hosts)
{
$Results1+=Get-VM–ComputerName $H | Get-VMHardDiskDrive |
Select-Object-Property @{n='Host';e={$_.ComputerName}}, VMName, Path, VMID |
Sort-Object-Property VMName
}
$Locations= @()
foreach ($Hin$Hosts)
{
$Locations+=Get-VM-ComputerName$H | Get-VMHardDiskDrive | Select-Object ComputerName,`
Path,VMName
}
$Results3= @()
foreach ($Locationin$Locations)
{
$FIle=$location.Path.ToString()
$Script="Get-ChildItem '$File'"
$Server=$Location.ComputerName
$Scriptblock=$ExecutionContext.InvokeCommand.NewScriptBlock("$Script")
$Results3+=Invoke-Command-ComputerName$Location.ComputerName-ScriptBlock$Scriptblock
| Select @{n='Computer';e={$_.PSComputerName}},Name,@{n='Size';e={$_.Length/ 1gb -as [int]}},`
@{n='Location';e={$File}}
}
$properties= @{
Host=$Locations.ComputerName;
'VMName'=$Locations.VMName;
'Size'=$Results3.Size;
'Location'=$Results3.Location
}
$FinalResults=New-Object–TypeName PSObject –Prop $properties
$FinalResults.Host,$FinalResults.Location,$FinalResults.Size,$FinalResults.VMName |
ConvertTo-Html-Title'VM Disk Stats' | Out-File$home\Desktop\test.html