VMware Cloud Community
michelmia
Contributor
Contributor

Build a scriprt that check all my VM's

Hi,

I would like your help with a script that I wont to create that will run ones a day and check if all my vm's are powered on and there nic cards is connected.

Can some one help me with the script?

4 Replies
scott28tt
VMware Employee
VMware Employee

Moderator: Thread moved to the PowerCLI area.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
LucD
Leadership
Leadership

You could do something like this

Get-VM -PipelineVariable vm |

ForEach-Object -Process {

    Get-NetworkAdapter -VM $vm |

    Select @{N='VM';E={$vm.Name}},

        @{N='PowerState';E={$vm.PowerState}},

        @{N='NIC';E={$_.Name}},ConnectionState

} | where{$_.PowerState -ne 'PoweredOn' -or $_.ConnectionState -ne 'Connected'}


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

Reply
0 Kudos
michelmia
Contributor
Contributor

Thank you for your help.

If I have a cupule of servers that I would like that if its powered off that the script will power them on and connect the nic card.

Reply
0 Kudos
LucD
Leadership
Leadership

You seem to be adding additional requirements to your original request.
Sorry, I stopped answering those.


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