jeep2004
Enthusiast
Enthusiast

need export to csv all vm in txt file

hi
need help
I need to export.csv  from list.txt file VMs that I have issue 
in export csv I need VM name , State (on or off) , folder name 
thanks 

0 Kudos
23 Replies
Macleud
Enthusiast
Enthusiast

Hi.

You need to add:

 

@{N='ToolsVersionStatus';E={$vm.ExtensionData.Guest.ToolsVersionStatus}}

 

0 Kudos
LucD
Leadership
Leadership

No need to go into the ExtensionData, you can do

Get-VM -Name $vmNames -PipelineVariable vm |
Get-NetworkAdapter -PipelineVariable nic |
Select-Object @{N = 'VM'; E = { $vm.Name } },
@{N = 'PowerState'; E = { $vm.PowerState } },
@{N = 'CPU'; E = { $vm.ExtensionData.Config.Hardware.NumCpu } },
@{N = 'CoresPerSocket'; E = { $vm.ExtensionData.Config.Hardware.NumCoresPerSocket } },
@{N = 'NIC'; E = { $nic.Name } },
@{N = 'Connected'; E = { $nic.ConnectionState.Connected } },
@{N = 'IP'; E = { ($vm.Guest.Nics | Where-Object { $_.Device.Name -eq $nic.Name }).IPAddress -join '|' } },
@{N='ToolsStatus';E={$vm.Guest.State}} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture


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

0 Kudos
jeep2004
Enthusiast
Enthusiast

Hi guys 

I need info about ToolsVersionStatus

like "Running, version:10305 (Upgrade available)" or "Running, version:11333 (Guest Managed)"

 can you help me please with my Script ? 

$vmNames = get-vm
$vmNames | Select -ExpandProperty $vmNames1

$vmNames = get-content "C:\temp\Scripts\changeCPU\cpu.txt" # (Optional from TXT File)
$Report_All_Info = "C:\temp\Scripts\changeCPU\Report_All_Info.csv"

Get-VM -Name $vmNames -PipelineVariable vm |
Get-NetworkAdapter -PipelineVariable nic |
Select @{N='name';E={$vm.Name}},
@{N = 'PowerState';E={$vm.PowerState}},
@{N = 'Guest OS';E={$vm.Guest.OSFullName}},
@{N = 'Folder';E={$vm.Folder.Name}},
@{N = 'ToolsVersion';Expression={$vm.Guest.ToolsVersion}},
@{N = 'Total_CPU';E={$vm.NumCpu}},
@{N = 'CoresPerSocket';E={$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N = 'CPU Per Sockets ';E={$vm.NumCpu/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}}, #( Calculator the vCPU /CoresPerSocket)
@{N = 'NIC';E={$nic.Name}},
@{N = 'Connected';E={$nic.ConnectionState.Connected}},
@{N = 'IP';E={($vm.Guest.Nics | Where-Object { $_.Device.Name -eq $nic.Name }).IPAddress -join '|'}} |

Export-Csv -Path $Report_All_Info -NoTypeInformation -UseCulture

Tags (1)
0 Kudos
LucD
Leadership
Leadership

That is not the ToolsVersionStatus but a concatenation of 3 separate properties.
It would have helped if you said what you wanted to see.

 

 

Get-VM -Name $vmNames -PipelineVariable vm |
Get-NetworkAdapter -PipelineVariable nic |
Select-Object @{N = 'VM'; E = { $vm.Name } },
@{N = 'PowerState'; E = { $vm.PowerState } },
@{N = 'CPU'; E = { $vm.ExtensionData.Config.Hardware.NumCpu } },
@{N = 'CoresPerSocket'; E = { $vm.ExtensionData.Config.Hardware.NumCoresPerSocket } },
@{N = 'NIC'; E = { $nic.Name } },
@{N = 'Connected'; E = { $nic.ConnectionState.Connected } },
@{N = 'IP'; E = { ($vm.Guest.Nics | Where-Object { $_.Device.Name -eq $nic.Name }).IPAddress -join '|' } },
@{N='ToolsVersion';E={
        "{0}, version {1}, {2}" -f $vm.Guest.ExtensionData.GuestState,
        $vm.Guest.ExtensionData.ToolsVersion,
                $vm.Guest.ExtensionData.ToolsVersionStatus }
} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture

 

 

 


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