Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PowerCLI script batch and some commonly used automatic operation scripts

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Create virtual machines in batches using the specified template

# define parameters param ([string] $VMname, [string] $vmhostname, [string] $datastore) [string] $template) # add powercli module try {add-pssnapin vmware.vimautomation.core-ErrorAction SilentlyContinue} catch {} # Connect VsphereConnect-VIServer-server Vsphere-Protocol https-User user-Password passwordforeach ($I in 1.. 5) {$fullname = $VMname + "-" + $inew-vm-name $fullname-template $template-host $vmhostname-datastore $datastore} disconnect-viserver-confirm:$false when executing the file.\ scriptfile.ps1 VMname vmhost datastore template# does not declare parameters Parameters or.\ screptfile.ps1-VMname vmname-template template-vmhostname vmhost-datastore datastore# must be entered in the order specified by param. When the parameters are declared, the order of parameters can be changed at will

Batch restart is running virtual machines with similar names that can be matched

# add the powercli module try {add-pssnapin vmware.vimautomation.core-ErrorAction SilentlyContinue} catch {} # Connect VsphereConnect-VIServer-server Vsphere-Protocol https-User user-Password password# to define the regular expression $matchname= "^ [a-zA-Z] +\ d {5} ([a-zA-Z] {1mem4})? (\ w)? ([a-zA-Z] {3})? (\ d +)?" # restart the matching virtual machine Get-Cluster -Name cluster | Get-VM | where {$_ .Name-match $matchname-and $_ .PowerState-eq "PoweredOn"} | Restart-VM-RunAsyncdisconnect-viserver-confirm:$false

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report