PowerCLI script optimasation vm name power STATE &; vmware tool guest status.
Get-vmhost-xxxxxxxxxxxx name | where {$_.powerstate - not power "off"} | Get - vm | % {get-view $_.id} | Select Name, @{Name = "ToolsVersion"; {Expression = {$_.config.tools.toolsVersion}}, @{Name = "ToolStatus"; Expression = {$_.} Guest.ToolsVersionStatus}}
Output as shown below:-it does not show the STATUS of POWER & GUEST OS?
Name ToolsVersion ToolStatus
---- ------------ ----------
750 guestToolsNeedUpgrade 8300
2229 8300 guestToolsNeedUpgrade
2122 8300 guestToolsNeedUpgrade
2816 9221 guestToolsCurrent
Try like this
Get-VMHost-xxxxxxxxxxxx name | where {$_.powerstate - not power "off"} |
Get - VM |
Select Name, PowerState,
@{N = "GuestOS"; E={$_. ExtensionData.Guest.guestFullName}},
@{Name = "ToolsVersion"; Expression = {$_.} ExtensionData.config.tools.toolsVersion}},
@{Name = "ToolStatus"; Expression = {$_.} ExtensionData.Guest.ToolsVersionStatus}}
Tags: VMware
Similar Questions
-
How to use PowerCLI to report on the parameters of VMware Tools?
Anyone know what the script would be to report on the configuration of the VMware Tools on a virtual computer running? What I'm really interested by creates a report telling me if VMware Tools is configured to synchronize the time with the host.
Thank you!
To see what comments to synchronize their time with the host country, you can use this script
foreach($vm in Get-VM){ $row = "" | Select Name, ServerTimeSync $row.Name = $vm.Name $row.ServerTimeSync = $vm.ExtensionData.Config.Tools.SyncTimeWithHost $row }
____________
Blog: LucD notes
Twitter: lucd22
-
PowerCLI script for datacenter clusters and is, ANDS vm guests in a CSV file.
HI -.
I need help to write a script powercli that collect information vcenter such as the list of each Datacenter and its clusters, hosts and vm in a CSV file.
Thanks in advance!
-Philippe.
You can do something like this.
But be aware that it will not report VMHost, Clusters and data centers that do not have any virtual computer in them.
{foreach ($dc in Get-Data Center)
foreach ($cluster Get-cluster-location $dc) {}
foreach ($esx in Get-VMHost-location $cluster) {}
Get-VM-location $esx |
Select @{N = 'Center'; E = {$dc. Name}},
@{N = "Cluster"; E = {$cluster. Name}},
@{N = "$vmhost"; E = {$esx. Name}}, name
}
}
}
-
Conclusion VM power state is imprecise
I use the following script to determine the power state of virtual machines. Regardless of the actual situation, the result of this script is powerOn. Thank you.
Script:
$VIServer = $Args [0]
$Image = $Args [1]
$User = $Args [2]
$Password = $Args [3]
$FilePath = "C:\Vmware_Healthcheck\Status_$Image.txt".
Add-PSsnapin VMware.VimAutomation.Core
Initialize - VIToolkitEnvironment.ps1
to connect-viserver-Server $VIServer - user $User-password $Password
$vm = get-View - ViewType VirtualMachine-filter @{"Name" = "$Image"}
$hostView = get-View - ID $vm. Runtime.Host
$hostView.Summary.Runtime | Out-file - FilePath $FilePath
Disconnect-VIServer-confirm: $False
Result:
ConnectionState: connected
PowerState: receiving
InMaintenanceMode: false
Distribution: 2009-04-30 15:05:19
HealthSystemRuntime: VMware.Vim.HealthSystemRuntime
DynamicType:
DynamicProperty:
Looks like you return a power of the host State, I think that...
$hostView.Summary.Runtime | Out-file - FilePath $FilePath
Take a look at http://www.vmwarescripting.com/index.php?topic=550.msg758#new
-
Get information about the VM name, owner, State of the Machine and tools State
Hello
I want to write a script to get information about the name of VM, owner, status of the Machine and tools State, because I'm a beginner in powershell I couldn't find any solution yet.
I know how to get the name of the virtual machine and the owner
Get-VM | Get-Annotation -CustomAttribute Owner | select AnnotatedEntity, Value
and how to find the tools and the State of the machine
Get-VM | Select-Object -Property Name,@{N="State";E={$_.Guest.State}},@{N="ToolsStatus";E={$_.Guest.ExtensionData.ToolsStatus}}
Unfortunately I don't find a way to merge the two applications.
Can someone help me please?
Kind regards.
SaPu
Try it like this
Get - VM | Select-Object - property Name,@{N="State; E={$_. Guest.State}},
@{N = "ToolsStatus"; E={$_. Guest.ExtensionData.ToolsStatus}},
@{N = "AnnotatedEntity"; E = {$attr. AnnotatedEntity}},
@{N = "Owner"; E = {(Get-Annotation-entité $_-CustomAttribute «Propriétaire»).} Value}} -
Hello
I tried to create a script to find the Versions of VMWare-Tools installed on my guest to view and write to a CSV file.
Here´s content:
$vmview = get - VM | Sort-Object {$_.} Name} | Get-View
$vmview. Config.Tools | Select ToolsVersion. Write-Host # | Export-CSV "C:".
' Script_Outputs\VM_Tools_Version_$ Wann.csv '-noTypeInformationMy problem is:
The script shows the Version of the tools installed, but it doesn´t show the name
How can I add the name of the script?
THX in advance
Chakoe
Of course, something like that
Get-VM |Sort-Object {$_.Name} | Get-View | ` where {$_.Config.Tools.ToolsVersion -eq "7202"} | ` Select Name, @{N="Version";E={$_.Config.Tools.ToolsVersion}}
____________
Blog: LucD notes
Twitter: lucd22
-
VMware Tools after upgrade to ESXi Update 3
I recently tested the upgrade of one of our hosts of update 2 to 3 update. After you apply the update using Update Manager virtual machines running on the host State VMware Tools ToolsOK instead of the ToolsOutOfDate show expected. It seems that there is indeed a new version of the tools installed with the update 3, but virtual Centre is not correctly state.
All the world has noticed this problem?
This is a known issue. I would recommend to use for free a 3rd third party tool to check the version numbers:
http://www.yellow-bricks.com/2008/11/12/cool-tool-update-RVTools-21/
Duncan
Blogs: http://www.yellow-bricks.com
If you find this information useful, please give points to "correct" or "useful".
-
Is there a Script to install VMware tools on any event of power off?
Hi all
Currently, we have an infrastructure VM 1000 + reversed between 2 data centers and are moving from 5.1 to 5.5 ESXi.
We want to make sure on the new architecture of 5.5 is that any virtual computer that VMware tools installed - it installs on any event powercycle.
Y at - it a script of mass that we could run for linux servers and windows can this factor?
At the moment we have 700 VMs have the tools installed and up-to-date
100 or more, who have installed and are not updated
200 + remaining machines do not have the tools installed, and we want to automate to install the tools on any event of power cycle.
For the 100 who are not up-to-date
We followed the following tasks and confirmed that it works
If a virtual machine with obsolete tools will automatically update on a power cycle
But the 200 who need complete installation tools stop - we need help to get a script to work / if there is one that can do this
We can use the following to update the tools to the power cycle
1
2
3
4
5
6
7
8
$vm
= Get
-VM
-Name
"virtualmachine"
$spec
=
New-Object
VMware.Vim.VirtualMachineConfigSpec
$spec
.changeVersion =
$vm
.ExtensionData.Config.ChangeVersion
$spec
.tools =
New-Object
VMware.Vim.ToolsConfigInfo
$spec
.tools.toolsUpgradePolicy =
"upgradeAtPowerCycle"
$_this = Get
-View
-Id
$vm
.Id
$_this.ReconfigVM_Task(
$spec
)
But we want something that can install the tools if not installed on the Cycle of power rather than update / update...
Hope that makes sense and that theres a script that we can use to do this.
Thank you all
The 1st real time installation of the VMware Tools is AFAIK not possible with a PowerCLI cmdlet.
You will need to use a method of SW distribution, that you will use to install any SW on your workstations.
In your case, you will need to support Win and Linux machines virtual, so you will need to provide at least 2 procedures to perform the actual installation.
Some additional info can be found in Re: how to use PowerCLI install VMware Tools?
-
I want to move virtual machines to a folder called Linux name, but we have several file of the same name in our Datacenter, please give me PowerCLI Script to move exactly.
I tried to use for the function FolderByPath below, but don't know how to use it and have worked. Please help me in this.
Function Get-FolderByPath {}
< #.
. Records of recovery SYNOPSIS by giving a path
. DESCRIPTION the function will retrieve a record by its
path. The path can contain any type of leave (folder or)
Data Center).
. Author NOTES: Luc relaxing
. Path PARAMETER
The path to the folder.
This is a required parameter.
. Path PARAMETER
The path to the folder.
This is a required parameter.
. PARAMETER separator
The character used to separate the leaves in the
path. The default value is ' / '.
. EXAMPLE OF
PS > Get-FolderByPath-path ' Datacenter/Folder1/Folder2 ".
. EXAMPLE OF
PS > Get-FolderByPath-path "Folder1 > Folder2"-separator ' > '
# >
(param
[CmdletBinding()]
[parameter (Mandatory = $true)]
[System.String []] ${Path}.
[tank] ${delimiter} = ' / '.
)
{in process
If (((Get-PowerCLIConfiguration).)) DefaultVIServerMode - eq "Multiple") {}
$vcs = $defaultVIServers
}
else {}
$vcs = $defaultVIServers [0]
}
{foreach ($vc to $vcs)
{foreach ($strPath in $Path)
$root = get-file-name of the server data $vc centers
$strPath.Split ($Separator) | %{
$root = get-inventory-name $_-location $root - server $vc - NoRecursion
If ((Get-stocks-localisation $root-NoRecursion |)) Select--ExpandProperty name)-contains "vm") {}
$root = get-inventory-name "vm" - location $root - server $vc - NoRecursion
}
}
$root | where {$_-is [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]}|% {}}
Get-file-name $_. Name - location $root. Parent - Server $vc
}
}
}
}
}
You can try to retrieve the object file by steps as well.
Something like this for example
$folder = get-data center-name 'LTX01-G8 | Get-file-name "LTX-servers | Get-file-name "LTX servers 0000 - 0299. Get-file-name Linux
I guess the first qualification in your path was the data center.
-
I came across a very strange question. I tried to create some custom vmware scripting tools, such as a new .bat file. This file contains a large number of orders, mostly as copy command "copy file://\\192.168.172.5\abc.exe c:\. ». I set this file as a custom script for Script event - power on guest operating system. Everything goes well with the bat file when I tested it. But after that I changed the State of power to power on, all other commands work fine except the copy commands in the bat file. Why? How can I make it work? Of course the problem of network. And that makes me very confused.
Hello
First copy the files on local disk was OK.
If this works for local disk, but not to a network drive, then hit you indeed a permissions issue any.
But if I run the script with tools VMware service script, the commands of copy (of the remote shared folder) failed while other controls worked well. I'm quite confused.
In fact, it is easily explained. The VMware tools service (Yes, it's a service) runs under the account Local system and by default, the local system account has no access to the network for security reasons. You can change the user of the service runs under and see if that solves your problem (very likely)
To do this, go to computer management (right-click icon desktop, select 'Manage') and open Services and Applications, service page, locate the VMware Tools service in the list. Select properties, log on to the page tabs and change account at your own Local System account. Restart the service and it should work.
--
Wil
_____________________________________________________
Visit the new VMware developers at http://www.vi-toolkit.com wiki
-
Define custom tools VMware of PowerCLI scripting?
Hello
I wonder if it is possible, from PowerCLI, define scripts custom in VMware Tools. These are the scripts that run when you suspend/resume/etc...
I looked in the docs and online and here and could not find anything. Do you need to use the VIX api for this?
Thank you
Mike
There are 2 options:
(1) you re-use the existing files of bat on reviews
(2) you specify a .BAT file
For the 2nd option you will require, as pointed out by William, the VIX API.
But for the first method you can do it with the current generation of PowerCLI
This script changes the content of the file by default poweroff BAT.
$vmName =
$powerOffBatName = "poweroff-vm-default.bat" $getProgPath = "echo %ProgramFiles%" $newPowerOffBat = @" Rem New PowerOff script dir "@ # Store new bat file locally Set-Content -Path ($env:temp + "\" + $powerOffBat) -Force -Value $newPowerOffBat $vmImpl = Get-VM $vmName $vm = $vmImpl | Get-View # rem Get credentials $guestCred = Get-Credential -Credential "guestuser" $hostCred = Get-Credential -Credential "hostuser" # Get the content of %ProgramFiles% on the guest $progPath = (Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred ` -VM $vmImpl ` -ScriptText $getProgPath -ScriptType "Bat").Trim() # Set the path of the file $powerOffBatPath = $progPath + "\VMware\VMware Tools\" # Remove the read-only attribute $unsetRO = 'attrib -R "' + $powerOffBatPath + $powerOffBat + '"' Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred ` -VM $vmImpl ` -ScriptText $unsetRO -ScriptType "Bat" # Copy the new file $destFile = $powerOffBatPath + $powerOffBat Copy-VMGuestFile -Source ($env:temp + "\" + $powerOffBat) ` -Destination $destFile ` -GuestCredential $guestCred ` -HostCredential $hostCred ` -LocalToGuest -VM $vmImpl # Set the read-only attribute $setRO = 'attrib +R "' + $powerOffBatPath + $powerOffBat + '"' Invoke-VMScript -GuestCredential $guestCred -HostCredential $hostCred ` -VM $vmImpl ` -ScriptText $setRO -ScriptType "Bat" # Activate the option to run a script $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.tools = New-Object VMware.Vim.ToolsConfigInfo $spec.tools.beforeGuestShutdown = $true $vm.ReconfigVM_Task($spec) Note that these default files BEATS all are set to read-only, so that changes to the script that assigns and assigns it back afterwards.
To make the script work on different flavors of Windows, it gets the path of the environment variable %ProgramFiles% % on the guest.
And to make sure that the script defines also the option of script run VMware Tools for action from extinction.
It should be relatively simple to change this for all the other options like suspend, restart, resume...
I would like to know if it's a little what you are looking for?
____________
Blog: LucD notes
Twitter: lucd22
-
Hi all, I am new to this community. I recently installed VMWare Workstation 7 on a Debian Lenny (kernel 2.6.26.2 - amd64). I had no problem with it, but when I tried to start a Virtual Machine Windows Vista, which I created it, does not start. Error says windows "cannot change the power state of VM: could not find a peer valid to connect to". "" Any idea, please?
Josber.
It seems that the virtual machine has been suspended when your host is using a different screen resolution
either change back to the resolution that you used when you suspenmded the machine virtual or delete the VMS.
This will force the VM to do a cold boot
___________________________________
-
PowerCLI Script to the report on the failed VM jobs
I figured out how to report on the events of VM (get-vievent), but no has no stains of VM. If a snapshot of the virtual computer fails, sometimes it never connect the events of the VM, but lists an error on the display of tasks. We are trying to monitor the clichés failed since its part of our backup solution.
I was looking for a way to report these tasks/failure of events in a daily report, or simply add to the daily report of amazing Alan Renouf that we use.
does anyone have any suggestions? For an example, see the attached screenshots. See how, in the view tasks, you have mistakes, but in the view of events, there is no errors.
Any help would be great. Thank you!
Jeff
PowerCLI Script to the report on the failed VM jobsI figured out how to report on the events of VM (get-vievent), but no has no stains of VM. If a snapshot of the virtual computer fails, sometimes it never connect the events of the VM, but lists an error on the display of tasks. We are trying to monitor the clichés failed since its part of our backup solution.
I was looking for a way to report these tasks/failure of events in a daily report, or simply add to the daily report of amazing Alan Renouf that we use.
does anyone have any suggestions? For an example, see the attached screenshots. See how, in the view tasks, you have mistakes, but in the view of events, there is no errors.
Any help would be great. Thank you!
Jeff
Hi Jeff
I had exactly the same need to identify stereotypes having failed and drilled until SDK and LucD suggestions (thank you) to encode the following lines:
$vmlist = Get-VM |sort Name foreach ($guestname in $vmlist) { $hours = 48 # Number of hours back $tasknumber = 999 # Windowsize of the Task collector $taskMgr = Get-View TaskManager # Create hash table. Each entry is a create snapshot task $report = @{} $filter = New-Object VMware.Vim.TaskFilterSpec $filter.Time = New-Object VMware.Vim.TaskFilterSpecByTime $filter.Time.beginTime = (Get-Date).AddHours(-$hours) $filter.Time.timeType = "startedTime" $collectionImpl = Get-View ($taskMgr.CreateCollectorForTasks($filter)) $dummy = $collectionImpl.RewindCollector $collection = $collectionImpl.ReadNextTasks($tasknumber) while($collection -ne $null){ $collection | where {$_.DescriptionId -eq "VirtualMachine.createSnapshot" -and $_.EntityName -eq $guestName} | %{ if ($_.State -eq "Error") { write-host $_.EntityName write-host $_.StartTime write-host $_.State } else { } } $collection = $collectionImpl.ReadNextTasks($tasknumber) } $collectionImpl.DestroyCollector() }
This script displays the name of the virtual machines which met with an instant failure in the last 48 hours (a variable, you can change)
This is just the beginning, because I want to count the shots failed and identify virtual computers that have more than 2 in 2 days
Feel free to alter it at will.
Enjoy
Eric
-
OK, this problem beautifully undescriptive I've seen caused by what seems to be dozens of things happening for me.
I made the mistake of horrible update my FC8 kernel to the latest one (2.6.26.8 - 57.fc8). Mind you, that's all that's changed. It was with a 1.06 server with happiness and perfectly good computers running virtual in use before the upgrade.
After the new kernel and reboot, I had to rebuild vmmod. I had to get a fix of any - any later that I used with my previous kernel (116 does not solve the problem of compiling) so I used all-any117d. Update like a champion.
Try to turn on a VM and Ihanta!, the above error.
Nothing else was changed.
I tried the upgrade to VMware Server 1.08. Used all-new any117d - update OK.
Error again.
I have re-run the compilation, this time to say 'yes' to what the installation script to "adjust the permissions of all virtual machines in xxxlist" or whatnot.
Error again.
status of /etc/init.d/VMware
Networking networking on/dev/vmnet0 is running
Invited only on/dev/vmnet1 network is running
Network invited only on/dev/vmnet8 is running
NAT networking on/dev/vmnet8 is running
Responsible vmmon module
Loaded module Vmnet
FWIW, I compile as long as root, but have always run VMware server from my UID nonroot.
What now?
I'm in the same boat. Fedora 8 2.6.26.8 - 57.fc8 #1 SMP
I have tried uninstalling/reinstalling v1.0.6 thru 1.0.8 with all 116 updates and 117d. 117D compiles with every version of server but when I try to turn on a virtual computer I get this error.
Cannot change the power state of virtual machine: the process has exited with an error:
vmxvmdb: name of the Index generated by the configuration file
POST (no connection): Version mismatch with vmmon module: expected 138.0, obtained 168.0.
You have a bad version of the module kernel "vmmon.
Try reinstalling VMware Server.
POST (no connection): failed to initialize the surveillance apparatus.
Failed to initialize the virtual machine.
End of the error message.
I found several posts other people have this problem but
they are months with no recent activity and nothing that solved the problem. I found appeared
to get a fix, one updated the all an update that corrects the problem for
2.6.26 performing several nuclei, but the link for the update on TI-psycho appears to be dead. Here is the link to the discussion
http://Fedoraforum.org/Forum/showthread.php?t=199026&page=2
Of course, I would like to know how to solve this problem as well.
Thank you
-
in my inventory and what RV tools scripts out I get the version of the OS that is selected for the virtual machine to change settings - options - version. I would also like to produce a list of the version of the OS that signal the VMware tools in order to find those with poorly chosen OS and fix them. I tried to. ExtensionData.config.Tools and I do not see the operating system listed there, anyone know where it is?
PowerCLI C:\Program Files (x 86) \VMware\Infrastructure\vSphere PowerCLI > $vm1.extensiondata.config.tools
ToolsVersion: 9354
AfterPowerOn: true
AfterResume: true
BeforeGuestStandby: true
BeforeGuestShutdown: true
BeforeGuestReboot:
ToolsUpgradePolicy: upgradeAtPowerCycle
PendingCustomization:
SyncTimeWithHost: true
LastInstallInfo: VMware.Vim.ToolsConfigInfoToolsLastInstallInfo
DynamicType:
DynamicProperty:
aside, where can note I find a resource that shows what options are available for each command get, such as get-host and get - vm? I learn a lot about what I can find in powercli by running this command and explore those who returns VMware.Vim..., but would allow me to save a lot of time to be able to just go get him.
PowerCLI C:\Program Files (x 86) \VMware\Infrastructure\vSphere PowerCLI > $vm1 = get - vm test-vm1
PowerCLI C:\Program Files (x 86) \VMware\Infrastructure\vSphere PowerCLI > $vm1.extensiondata
Capacity: VMware.Vim.VirtualMachineCapability
Config: VMware.Vim.VirtualMachineConfigInfo
Layout: VMware.Vim.VirtualMachineFileLayout
LayoutEx: VMware.Vim.VirtualMachineFileLayoutEx
Storage: VMware.Vim.VirtualMachineStorageInfo
EnvironmentBrowser: EnvironmentBrowser-envbrowser-653
ResourcePool: ResourcePool-resgroup-11
ParentVApp:
ResourceConfig: VMware.Vim.ResourceConfigSpec
Duration: VMware.Vim.VirtualMachineRuntimeInfo
Comments: VMware.Vim.GuestInfo
Summary: VMware.Vim.VirtualMachineSummary
Data store: {Datastore-datastore-591}
Network: {Network-network-145}
In summary:
RootSnapshot: {}
GuestHeartbeatStatus: Green
LinkedView:
Parent: File-group-v.41
CustomValue: {}
OverallStatus: Green
ConfigStatus: Green
ConfigIssue: {}
EffectiveRole: {-1}
Authorization: {}
Name: test-vm1
DisabledMethod: {UnregisterVM, RevertToCurrentSnapshot_Task, Destroy_Task, RemoveAllSnapshots_Task...}
RecentTask: {}
DeclaredAlarmState: {10.vm - alarm-653, alarm - 11.vm - 653, 653 - 2.vm - alarm, alarm - 23.vm - 653...}
TriggeredAlarmState: {}
AlarmActionsEnabled: true
Tag : {}
Value : {}
AvailableField: {FA. GosAgent}
MoRef: VirtualMachine-vm-653
Client: VMware.Vim.VimClientImpl
Try $vm. ExtensionData.Guest.GuestFullName
Maybe you are looking for
-
Serious CD - r media player won't play in my CD player
The CD I burned media player will not play in my CDR compatible CD player. I had success in the past with my CD player, but now they will not play in my CD player. Yes, the CD drive is compatible with the CD - Rs. I use this system to work much as
-
Explore cannot display the pageVista updatesRestart
-
How no one hiding a list box? I want to overlay several areas hidden from the list, then press a command button to display a list box. What a ListBox will be visible at any time. There will always be a visible list box. Thank you.
-
Should LiveOne care be more?
I use LiveOne care. He does all this? Or should I also be using other protections and verification of software, running stuff like AdWare, Skybot and other stuff like these two? Appreciate any feedback. M
-
Disable the automatic reduction of Windows in Windows 7
I often work with multiple open windows. Sometimes (but not always) when I'm dragging a window autour, Windows minimizes all other windows without apparent reason. This does not usually happen, but it does for me maybe once a week, apparently at ra