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
What do you already have?
And where do you need help?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks for replay
-------------------
$credential = Get-Credential
$Username = $credential.GetNetworkCredential().username
$Password = $credential.GetNetworkCredential().password
$vcenter1 = "xxx" #VC Prod
$VM_list = Get-Content -Path C:\temp\VMList.txt
-------------------
this what I have
You could do something like this
Get-Content -Path C:\temp\VMList.txt |
ForEach-Object -Process {
Get-VM -Name $_ |
Select Name, PowerState, @{N='Folder';E={$_.Folder.Name}}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
THX
its work
hi
I run again the scripts
and i get error message
Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or
empty. Provide an argument that is not null or empty, and then try the command
again.
At line:2 char:18
+ Get-VM -Name $_
why ?
What exactly is in your TXT file?
How did you run the code?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
in txt file only VMs list
like
vm01
vm02
vm03
this is my scripts
------------------------------------
$credential = Get-Credential
$Username = $credential.GetNetworkCredential().username
$Password = $credential.GetNetworkCredential().password
$vcenter = "vSphere"
Connect-VIServer $vcenter -User $Username -Password $Password
Get-Content -Path C:\temp\VMList.txt
ForEach-Object -Process {
Get-VM -Name $_ |
Select Name, PowerState, @{N='Folder';E={$_.Folder.Name}}
} | Export-Csv -Path C:\temp\report.csv -NoTypeInformation -UseCulture
-------------------------------------
You left out the pipeline symbol at the end of the Get-Content line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok
I got it
many thanks
hi
If I want to report the PowerState and Ip address in the same scripts
how do it add in the same script?
THX
The PowerState is already in the snippet I posted earlier.
To get the IP address you need to have the VMware Tools installed.
Is that the case?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes , all VMs with vmTools installed
this is my scripts...
$reportCPU = "C:\temp\reportCPU.csv"
Get-VM -Name $vmNames|
Select Name,Get-NetworkAdapter,PowerState,
@{N='CPU';E={$_.ExtensionData.Config.Hardware.NumCpu}},
@{N='CoresPerSocket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture
but the table "Get-NetworkAdapter" is empty
You will need a calculated property, not just a cmdlet on the Select-Object.
And the Get-NetworkAdapter will not give you the IP address.
$reportCPU = "C:\temp\reportCPU.csv"
Get-VM -Name $vmNames|
Select Name,
@{N='VniC';E={(Get-NetworkAdapter -VM $_).Name -join '|'}},
PowerState,
@{N='CPU';E={$_.ExtensionData.Config.Hardware.NumCpu}},
@{N='CoresPerSocket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
you right
I need to know how I see after I power on the VMs if the network status is enable ( i know some time we have a bug )
so I thinking how to do export VMs about status network connection and IP address
in the same script
thanks and sorry that I not very clear
You could do something like this
Get-VM -Name $vmNames -PipelineVariable vm |
Get-NetworkAdapter -PipelineVariable nic |
Select @{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 '|'}} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thank you
hi again
in the same scripts , I need to verify the status ToolsVersionStatus
I know the command is get-view but I can't combine it together with my existing script
Would appreciate help
Thanks
You can add a calculated property.
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={$vm.Guest.ToolsVersion}} |
Export-Csv -Path $reportCPU -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks you ,
but I need a ToolsVersionStatus not ToolsVersion