CitizenRon
asked on
Report on all VM's "Power-on Boot Delay" value
I'm using the attached PowerShell code with the VI Toolkit (Snippet ID=710413) that I wrote to report on all virtual machines in my three VICs that have Snapshots.
I found the attached PowerShell code (Snippet ID=710418) that successfully sets the Boot Delay of the matching VMs to 10 seconds and it works fine for setting it.
I've been trying to figure out how to adapt the Boot Delay script to my Reporting script and have it report the Boot Delay value instead of the Snapshot details but I can't seem to figure out the proper way to have the Get-View cmdlet to show the Boot Delay instead of setting it.
Any assistance in this would be greatly appreciated.
I found the attached PowerShell code (Snippet ID=710418) that successfully sets the Boot Delay of the matching VMs to 10 seconds and it works fine for setting it.
I've been trying to figure out how to adapt the Boot Delay script to my Reporting script and have it report the Boot Delay value instead of the Snapshot details but I can't seem to figure out the proper way to have the Get-View cmdlet to show the Boot Delay instead of setting it.
Any assistance in this would be greatly appreciated.
Write-Host
$SepBarEqual = "=" * ($Host.UI.RawUI.WindowSize.Width - 1)
$ServerList = "VC1", "VC2", "VC3"
ForEach ($Server in $Serverlist) {
Connect-VIServer $Server | Out-Null
$ServerNameBox = "= ** "+$Server+" **"+" " * ($Host.UI.RawUI.WindowSize.Width - $Server.Length - 14)+"="
Write-Host $SepBarEqual -ForegroundColor Cyan
Write-Host $ServerNameBox -ForegroundColor Cyan
Write-Host $SepBarEqual -ForegroundColor Cyan
Get-VM | Get-Snapshot | Format-Table VM, Created, Name, Description -auto
}
Write-Host
$value = "10000"
Get-VM vm-KMSTest* | ForEach {
$vm = Get-View $_.Id
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value
$vm.ReconfigVM_Task($vmConfigSpec)
}
ASKER
From my experience, Get-VM doesn't do much by itself. It's mostly a linking object to pass to other cmdlets like Get-Snapshot in my first script or Get-View in the second. There's nothing returned from Get-Member that would indicate it contains BootOptions.
Thanks for the PadRight tip though, that works fine too and does shorten the code a bit for the $Server line. Funny, using PadRight actually makes the $SepBarEqual line longer though!
Hmm, looking again at the code that sets the BootDelay above...the actual thing doing the work is $vm.ReconfigVM_Task. The $vm object is created from the Get-View cmdlet so I'm guessing I need to look at the methods and properties of Get-View for this???
I'll check that out
Thanks for the PadRight tip though, that works fine too and does shorten the code a bit for the $Server line. Funny, using PadRight actually makes the $SepBarEqual line longer though!
Hmm, looking again at the code that sets the BootDelay above...the actual thing doing the work is $vm.ReconfigVM_Task. The $vm object is created from the Get-View cmdlet so I'm guessing I need to look at the methods and properties of Get-View for this???
I'll check that out
ASKER
Jackpot! Why is it always easier to figure out something after you ask someone else??!?
A Get-VM VM piped to Get-View has a Config property which has a BootOptions property which has a BootDelay property!
Here's my completed code for my Get-BootDelay.ps1 script that works nicely to show all VMs with a Boot Delay set...
For the points... Anyone want to help make this so that if I pass a VM Name (with or without wildcards) as a command line argument it will only report on those VMs whose name matches? I'm thinking the best place (for simplicity and speed purposes) to do it is at the "Get-VM | ForEach" spot on line 10 since Get-VM supports wildcards. Also, if I pass a command-line argument to Get-BootDelay.ps1, I want it to report the BootDelay even if it is zero.
So here's the modifications I need...
A Get-VM VM piped to Get-View has a Config property which has a BootOptions property which has a BootDelay property!
Here's my completed code for my Get-BootDelay.ps1 script that works nicely to show all VMs with a Boot Delay set...
For the points... Anyone want to help make this so that if I pass a VM Name (with or without wildcards) as a command line argument it will only report on those VMs whose name matches? I'm thinking the best place (for simplicity and speed purposes) to do it is at the "Get-VM | ForEach" spot on line 10 since Get-VM supports wildcards. Also, if I pass a command-line argument to Get-BootDelay.ps1, I want it to report the BootDelay even if it is zero.
So here's the modifications I need...
Get-BootDelay New*
This will show me the delay of all virtual machines in each VC server starting with "New", even if their delay is 0
Get-BootDelay *
This will show me the delay of all virtual machines in each VC server even if their delay is 0
Get-BootDelay
This will show me the delay of all virtual machines in each VC server only where the delay is greater than 0.
This will show me the delay of all virtual machines in each VC server starting with "New", even if their delay is 0
Get-BootDelay *
This will show me the delay of all virtual machines in each VC server even if their delay is 0
Get-BootDelay
This will show me the delay of all virtual machines in each VC server only where the delay is greater than 0.
Write-Host
$SepBarEqual = "=" * ($Host.UI.RawUI.WindowSize.Width - 1)
$ServerList = "VC1", "VC2", "VC3"
ForEach ($Server in $Serverlist) {
Connect-VIServer $Server | Out-Null
$ServerNameBox = "= ** "+$Server+" **"+" " * ($Host.UI.RawUI.WindowSize.Width - $Server.Length - 14)+"="
Write-Host $SepBarEqual -ForegroundColor Cyan
Write-Host $ServerNameBox -ForegroundColor Cyan
Write-Host $SepBarEqual -ForegroundColor Cyan
Get-VM | ForEach {
$VMView = Get-View $_.Id
If ($VMView.Config.BootOptions.BootDelay -gt 0) {
($_.Name).PadRight(40) + "Delay: " + $VMView.Config.BootOptions.BootDelay
}
}
}
Write-Host
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again Chris! Wonderful coding as always. This time I'm going to commit the Param stuff to long-term memory!
No access to these until Monday... but do you get BootOptions back anywhere from Get-VM?
It'll be possible to add it in provided you get it back.
I did wonder if this might simplify your first line a bit:
"= ** $Server **".PadRight($Host.UI.RawU
It'll pad to $Host.UI.RawUI.WindowSize.
Chris