分类目录归档:脚本

使用PowerCLI批量修改虚拟机内存

由于要修改一批VDI机器的内存,数量比较多,就拿出了PowerCLI来进行批量修改,命令如下:

Connect-VIServer -Server vcenter.test.local -User admin -Password password

$VMs = Get-Cluster “Cluster” | Get-VM | Where { $_.Name -like “vdi-*” }

ForEach ($VM in $VMs) { Set-VM $VM -MemoryMB 2176 -Confirm:$False }

使用PowerCLI批量修改虚拟机的磁盘超时参数(Disk Timeout)

$VMs = Get-Cluster “Cluster” | Get-VM | Where { $_.PowerState -eq “PoweredOn” }
ForEach ($VM in $VMs) {
   $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine’, $VM.Guest.Hostname)
   Write-Host “Registry Value Before: “$VM.Guest.HostName “-” $reg.OpenSubKey(“SYSTEMCurrentControlSetServicesDisk”).GetValue(“TimeoutValue”)
 
   $regKey= $reg.OpenSubKey(“SYSTEMCurrentControlSetServicesDisk”,$true)
   $regkey.SetValue(‘TimeoutValue’,190,’DWord’)
 
   Write-Host “Registry Value After:  “$VM.Guest.HostName “-” $reg.OpenSubKey(“SYSTEMCurrentControlSetServicesDisk”).GetValue(“TimeoutValue”)
}