Hi folks,
Am trying a script which gets information about vmware applications installed from several windows vms.
The script is working fine, But I dont know how to make the output in a csv.
$VM = (Get-Content d:\Reports\input.txt)
foreach($vm in Get-VM -Name $VM)
{
$ScriptText1 = @"
get-wmiobject -class win32_product -filter "vendor like 'VMware%'" | select __SERVER, Name, Version, InstallDate
"@
Invoke-VMScript -VM $VM -ScriptText $ScriptText1 -GuestUser 'administrator' -GuestPassword 'welcome'
}
Any help?
I prefer using the transfer of the data in CSV format.
Something like this
$ScriptText1 = @"
Get-WmiObject -Class win32_product -Filter "vendor like 'VMware%'" |
select __SERVER, Name, Version, InstallDate | ConvertTo-Csv
"@
Get-Content d:\Reports\input.txt -PipelineVariable vm |
ForEach-Object -Process {
Invoke-VMScript -VM $vm -ScriptText $ScriptText1 -GuestUser 'administrator' -GuestPassword 'welcome' |
Select -ExpandProperty ScriptOutput |
ConvertFrom-Csv
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
Foreach does not place anything in the pipeline, while Foreach-Object does.
$ScriptText1 = @"
get-wmiobject -class win32_product -filter "vendor like 'VMware%'" | select __SERVER, Name, Version, InstallDate
"@
Get-Content d:\Reports\input.txt -PipelineVariable vm |
ForEach-Object -Process {
Invoke-VMScript -VM $VM -ScriptText $ScriptText1 -GuestUser 'administrator' -GuestPassword 'welcome' |
Select @{N='ScriptOutput';E={$_.ScriptOutput}}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Got the output like below
Length |
168 |
177 |
177 |
177 |
177 |
177 |
177 |
174 |
My bad, I corrected the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
It showing error, So I removed pipeline from this line
Select @{N='ScriptOutput';E={$_.ScriptOutput}} |
Now am getting the output, but I need to get each value in a separate cell
Output:
ScriptOutput |
__SERVER Name Version InstallDate -------- ---- ------- ----------- VM1 VMware Tools 11.2.5.17337674 20210418 VM1 VMware Dynamic Environment Manager 9.11.0.932 20210418 VM1 VMware Horizon Agent 7.13.0 20210418 |
__SERVER Name Version InstallDate -------- ---- ------- ----------- VM2 VMware Tools 11.2.5.17337674 20210418 VM2 VMware Dynamic Environment Manager 9.11.0.932 20210418 VM2 VMware Horizon Agent 7.13.0 20210418 |
There was a pipeline symbol at the end of the Select line, that shouldn't have been there.
I removed it
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes Lucd I corrected it.
But I need output like below format, Is it possible?
_Server | Name | Version | Install Date |
vm1 | VMware Tools | 11.2.5.17337674 | 20210418 |
vm1 | VMware Horizon Agent | 7.13.0 | 20210418 |
vm2 | VMware Tools | 11.2.5.17337674 | 20210418 |
The above script is printing as it is in the powershell console.
I prefer using the transfer of the data in CSV format.
Something like this
$ScriptText1 = @"
Get-WmiObject -Class win32_product -Filter "vendor like 'VMware%'" |
select __SERVER, Name, Version, InstallDate | ConvertTo-Csv
"@
Get-Content d:\Reports\input.txt -PipelineVariable vm |
ForEach-Object -Process {
Invoke-VMScript -VM $vm -ScriptText $ScriptText1 -GuestUser 'administrator' -GuestPassword 'welcome' |
Select -ExpandProperty ScriptOutput |
ConvertFrom-Csv
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD...Thats it