VMware Cloud Community
thisischristia1
Contributor
Contributor

Run Script for monitor_control.enable_softResetClearTSC only for a Specific Set of VMs - Windows 2012

This is the script found here: VMware Knowledge Base

I want to execute this without running on ALL VMs. How would i add a " Get-Content $ChangeMonitorcontrol | ForEach-Object " to the script below pointing it to a txt file of VM names?

ForEach ($vm in (Get-VM)){

$vmv = Get-VM $vm | Get-View

$name = $vmv.Name

$guestid = $vmv.Summary.Config.GuestId

$vmx = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmx.extraConfig += New-Object VMware.Vim.OptionValue

$vmx.extraConfig[0].key = "monitor_control.enable_softResetClearTSC"

$vmx.extraConfig[0].value = "TRUE"

if ($guestid -like "windows8*Guest") {

($vmv).ReconfigVM_Task($vmx)
}

}

10 Replies
thisischristia1
Contributor
Contributor

any ideas on this anyone?

0 Kudos
thisischristia1
Contributor
Contributor

Hello.. Can someone help me with this?

0 Kudos
daphnissov
Immortal
Immortal

This needs to be moved to PowerCLI (if a moderator can do that).

0 Kudos
a_p_
Leadership
Leadership

Discussion moved from ESXi to VMware PowerCLI

0 Kudos
a_p_
Leadership
Leadership

Create a text file vmlist.txt which contains the VM's names, and replace your script's first line with:

$vmlist = Get-Content -Path .\vmlist.txt

foreach ($vm in $vmlist) {

André

0 Kudos
LucD
Leadership
Leadership

You can do something like this.
Move the static object outside of the loop, use Get-View and use a combined filter.

$vmx = New-Object VMware.Vim.VirtualMachineConfigSpec

$extra = New-Object VMware.Vim.OptionValue

$extra.key = "monitor_control.enable_softResetClearTSC"

$extra.value = "TRUE"

$vmx.ExtraConfig += $extra

$vmFilter = @{

    Name = (Get-Content $ChangeMonitorcontrol ) -join '|'

    'Summary.Config.GuestID'='windows8.*Guest'

}

Get-View -ViewType VirtualMachine -Filter $vmFilter | %{

    $_.ReconfigVM_Task($vmx)

}


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

0 Kudos
thisischristia1
Contributor
Contributor

How would i get this value for all VMs Running Windows Server 2012 in the vCenter? In other words, I want to show a report of all VMs and output if it has the value or NOT.

The purpose is to know which VMs dont have the value.

0 Kudos
LucD
Leadership
Leadership

Do you have VMware Tools installed on all your VMs?


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

0 Kudos
thisischristia1
Contributor
Contributor

Yes all running VMware Tools.

0 Kudos
LucD
Leadership
Leadership

Try something like this

Get-VM | where{$_.Guest.OSFullName -match 'Windows Server 2012'} |

Select Name,

   @{N='enable_softResetClearTSC';E={

        $TSC = $_.ExtensionData.Config.ExtraConfig | where{$_.Key -eq 'monitor_control.enable_softResetClearTSC'}

        if($TSC){$TSC.value}else{'Not present'}}}


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

0 Kudos