Reputation: 57
I am making a script to run in powershell (powerCLI) for vmware. I try to do a automatic report exported to a csv file but i dont know how to resolve couple of problems.
All parameters which i dont know how to export them.
"virtual machine working location" I can export disks where is a mashine, but i don't know how to export all path with folders.
domain / workgroup
Name of computer When i try to export a name i get name with domain "name.domainname.com" (that is strange because my VM are not in domain, there are in workgroup) name i mean a name inside of OS not in esxi, because esxi name of vm i get from this
$name = (get-vm name_maschine|select-object name).name
or simple when in loop parameter is a name of mashine, i only export a parameter
less important parameters
4 . The name of vcenter in which host is working
Code:
connect-viserver -server IP-ADDRES -user root -password PASSWORD
Get-View -ViewType VirtualMachine | %{
New-Object PSObject -Property @{
# mashine name
'Mashine name' = $_.Name
#date when edited
'Date' = Get-Date
# resource pull
'pull' = (Get-VM $_.Name | Get-ResourcePool | select-object name).name
#disk where is mashine
'Datastore' = [system.String]::Join(",",($_.Storage.PerDatastoreUsage | %{Get-View $_.Datastore} | %{$_.Name}))
}
}
Upvotes: 1
Views: 1844
Reputation: 10097
I added extra parameters except domain/workgroup. To obtain that you will need to execute Invoke-VMScript
per each VM (with local admin credentials), combined with something like (Get-WmiObject Win32_ComputerSystem).Domain
$guestUser = "administrator"
$guestPass = "yourpass"
Get-View -ViewType VirtualMachine | %{
New-Object PSObject -Property @{
# machine name
'Machine name' = $_.Name
# machine name from vmware tools
'Guest name' = $_.Guest.HostName
# machine name from WMI
'Guest name(WMI)' = (Invoke-VMScript -VM $_.Name -GuestUser $guestUser -GuestPassword $guestPass -ScriptText {(Get-WmiObject Win32_ComputerSystem).Domain}).ScriptOutput
#date when edited
'Date' = Get-Date
# resource pool
'pool' = (Get-VM $_.Name | Get-ResourcePool | select-object name).name
#disk where is mashine
'Datastore' = [system.String]::Join(",",($_.Storage.PerDatastoreUsage | %{Get-View $_.Datastore} | %{$_.Name}))
# physical location
'VM Location' = $_.Config.DataStoreURL.URL
# vm host
'VM Host' = (Get-VM $_.Name).VMHost
# datacenter
'Datacenter' = (Get-Datacenter -VM $_.Name).Name
}
}
Upvotes: 1