powershell vmware powerCLI automatic script -
i making script run in powershell (powercli) vmware. try automatic report exported csv file dont know how resolve couple of problems.
all parameters dont know how export them.
"virtual machine working location" can export disks mashine, don't know how export path folders.
domain / workgroup
name of computer when try export name name domain "name.domainname.com" (that strange because vm not in domain, there in workgroup) name mean name inside of os not in esxi, because esxi name of vm this
$name = (get-vm name_maschine|select-object name).name
or simple when in loop parameter name of mashine, export parameter
less important parameters
4 . name of vcenter in host working
- the name of datacenter in host 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 mashine 'datastore' = [system.string]::join(",",($_.storage.perdatastoreusage | %{get-view $_.datastore} | %{$_.name})) } }
i added parameters except domain/workgroup. obtain need execute invoke-vmscript
per each vm (with local admin credentials), combined (get-wmiobject win32_computersystem).domain
$guestuser = "administrator" $guestpass = "yourpass" get-view -viewtype virtualmachine | %{ new-object psobject -property @{ # machine name 'machine name' = $_.name # machine name vmware tools 'guest name' = $_.guest.hostname # machine name 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 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 } }
Comments
Post a Comment