AutomationStat1
Contributor
Contributor

Get all VMs that automatically start with Host

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
25 Replies
LucD
Leadership
Leadership

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

0 Kudos
AutomationStat1
Contributor
Contributor

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?

0 Kudos
LucD
Leadership
Leadership

Correct


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

0 Kudos
abyssalone
Contributor
Contributor

This doesn't work for me

0 Kudos
Martin90
Contributor
Contributor

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.

0 Kudos
LucD
Leadership
Leadership

What doesn't work?

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


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

0 Kudos
Martin90
Contributor
Contributor

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.

 

0 Kudos
LucD
Leadership
Leadership

Start by updating your PowerCLI version


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

0 Kudos
Simply1
Contributor
Contributor

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

 

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Simply1
Contributor
Contributor

with this script i see vm on "Manual startup"

0 Kudos
LucD
Leadership
Leadership

Yes, is there a question in there?


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

0 Kudos
Simply1
Contributor
Contributor

sorry I forgot "?"

0 Kudos
LucD
Leadership
Leadership

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


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

0 Kudos
Simply1
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Simply1
Contributor
Contributor

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

0 Kudos
LucD
Leadership
Leadership

And what about

Get-vm | Get-VMStartPolicy


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

0 Kudos
Simply1
Contributor
Contributor

in this case i recived error

0 Kudos