Hi All,
I am trying to create a list of Windows VMs where I can do, but any export is filled with empty lines. Regardless of whether I use Export-CSV or Out-File when a VM is not Windows I get an empty line. I am trying to get a list to use as a Get-Content for another script to query the Guest OS using WMI.
The question is, is there an easy way to eliminate the empty lines?
Below is my code, and I just exchange Out-File for Export-CSV in my attempts. Out-File is better I think so I don't have the "" to contend with in my import of data in the other script.
$allvms = @()
$vmlist = Get-Vm | where {$_.PowerState -eq "PoweredOn"}
ForEach ($vm in $vmlist){
$vmv = $vm | Get-View
$vms = "" | Select Name #, OS
if ($vmv.Config.GuestFullName -match "Windows"){
$vms.Name = $vm.name
}
else{
}
$allvms += $vms
}
$allvms | Out-File "D:\temp\computers.txt"
I could probably get this script to call the WMI query data in this script, but as I will be generating several sets of computer names from other sources too, I want to run the scripts necessary.
Geoff