VMware Cloud Community
AutomationStat1
Contributor
Contributor
Jump to solution

Get all VMs that automatically start with Host

Script to get all VMs that automatically start with a host and remove the automatic startup functionality. Im not even sure how to start this. I imagine to find all VMs that start with a host, it would be something like this:

Foreach($VM in Get-VM) | Select-Object Name, AutomaticStartAction

But the above doesn't populate the AutomaticStartAction column. And I don’t know the command to remove the AutomaticStart Action

Any help would be appreciated Smiley Happy

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do

Get-VM | Get-VMStartPolicy | select VM,StartAction

For changing the setting, have a look at Powercli to set "manual start" of vm instead of 'automatic startup'?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
25 Replies
LucD
Leadership
Leadership
Jump to solution

You can do

Get-VM | Get-VMStartPolicy | select VM,StartAction

For changing the setting, have a look at Powercli to set "manual start" of vm instead of 'automatic startup'?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
AutomationStat1
Contributor
Contributor
Jump to solution

Thank you!! And i assume to change the policy to turn it off the command would be:

$vmstartpolicy = Get-VM | Get-VMStartPolicy

Set-VMStartPolicy -StartPolicy $vmstartpolicy -StartAction None

Is that correct?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Correct


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
abyssalone
Contributor
Contributor
Jump to solution

This doesn't work for me

Reply
0 Kudos
Martin90
Contributor
Contributor
Jump to solution

Get-VM | Get-VMStartPolicy | select VM,StartAction

 

this cmd doesn´t work for me. Could you help me extension of cmd with get-VM StartPolicy.

My case is that i need report of whole VM´s from my vcenter. Bcz when i try use cmd Get-VMStartPolicy - VM myvm function well, but I need for each other WM´s.

 

Thanks for answer.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What doesn't work?

Any error messages?
Which PowerShell and PowerCLI version?
Which vSphere version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Martin90
Contributor
Contributor
Jump to solution

1.] error messages - object reference not set to an instance of an object

2.] PowerCLI version - 6.5.0.234

3.] vsphere version - 6.7.0

 

target : Retrieves the start policy of the virtual machine´s.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Start by updating your PowerCLI version


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

I need export the VMStartpolicy with VMName, Host, Start action, start delay, start order

use this script:

Get-vm -Name "xxxyyy"  | Get-VMStartPolicy | select VM,StartAction,StartDelay,StartOrder,VMHost | Export-Csv "C:test.csv"

on the csv i see all infromation without vmhost

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Use a calculated property

Get-vm -Name "xxxyyy"  | Get-VMStartPolicy | 
select VM,StartAction,StartDelay,StartOrder,@{N='VMHost';E={$_.VM.VMhost.Name}} | 
Export-Csv "C:test.csv"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

with this script i see vm on "Manual startup"

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, is there a question in there?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

sorry I forgot "?"

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not the point, what would you expect it to show?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

i want see the vmname-startaction-startdelay-startorde-vmost

i run the script and generate csv file, into the file i see all information but wher the script running i receve a multiple error "

Get-VMStartPolicy: 09/27/2021 14:47:08 Get-VMStartPolicy Reference to an object not set to an object instance.
In row: 1 car: 11
+ Get-vm | Get-VMStartPolicy | select VM, StartAction, StartDelay, StartO ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo: NotSpecified: (:) [Get-VMStartPolicy], VimException
+ FullyQualifiedErrorId: Core_BaseCmdlet_UnknownError, VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMStartPolicy

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then there might be something wrong in your environment.
Orphaned VMs, ghost entries ....
Is a simple Get-VM producing the same errors?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

i run the get-vm | export-csv "c:test.csv" and no recived any error

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And what about

Get-vm | Get-VMStartPolicy


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Simply1
Contributor
Contributor
Jump to solution

in this case i recived error

Reply
0 Kudos