VMware Cloud Community
Patrick_85048
Contributor
Contributor

Powershell usage issues - updates fail

I am somewhat new to VMWare scripting and am trying to write some basic scripts. I usually test with 1 item before actually executing against the entire environment. My current script is trying to update CPU Shares Allocation. When I run the script, It seems to complete normally and actually enters an entry in the host event log for "Reconfigure Virtual Machine" but when I look at the results, there is nothing changed.

Here is a copy of my script (made generic for publication)

Connect-VIServer -Server 111.222.333.101 -Protocol https -User UUUUUUUU -Password PPPPPPPP

$vm = Get-View (Get-VM VMNAME).Id

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.CPUAllocation = New-Object VMware.Vim.ResourceAllocationInfo

$vmConfigSpec.CpuAllocation.Shares = New-Object VMware.Vim.SharesInfo

$vmConfigSpec.CpuAllocation.Shares.level = "custom"

$vmConfigSpec.CpuAllocation.Shares.shares = "1234"

$vm.ReconfigVM_Task($vmConfigSpec)

When executed, I get output that looks like this:

Name Port User

111.222.333.101 443 UUUUUUUU

Type : Task

Value : haTask-67890-vim.VirtualMachine.reconfigure-44556

I'm not sure what I'm missing to complete the update but when I look at the shares reservation online it remains at "normal" and "4000".

Any help would be greatly appreciated.

Thanks,

Patrick

0 Kudos
4 Replies
LucD
Leadership
Leadership

Where exactly are you looking at the shares reservation online ?

<Edit Settings> on the guest and then under the Resources tab ?

The script works and I see the changed CPU shares value.


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

0 Kudos
Patrick_85048
Contributor
Contributor

LucD - Thanks for the confirmation on the script. I am looking is the same place and my changes don't apply.

Am I missing some type of security setting or should I set privileges within the script to enable the updates?

0 Kudos
LucD
Leadership
Leadership

Let's first check if there any return code on the method.

Run your script like this

$vm = Get-View (Get-VM PC2).Id
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.CPUAllocation = New-Object VMware.Vim.ResourceAllocationInfo
$vmConfigSpec.CpuAllocation.Shares = New-Object VMware.Vim.SharesInfo
$vmConfigSpec.CpuAllocation.Shares.level = "custom"
$vmConfigSpec.CpuAllocation.Shares.shares = "1234"
$taskMoRef = $vm.ReconfigVM_Task($vmConfigSpec)

$task = Get-View $taskMoRef
while($task.info.state -eq "running" -or $task.info.state -eq "queued"){$task = Get-View $taskMoRef}

$task.info | select *

What versions/builds are you using ?

PS, VITK, ESX, VC


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

0 Kudos
Patrick_85048
Contributor
Contributor

LucD, Thanks for the script suggestion.

My versions are: ESX3.0.2 Update 1, VC 2.0.2, VIToolkit 1.5 and PowerShell 1.0

After running the new version of the script, here's the output:

Name Port User

-


-


-


111.222.333.101 443 root

Key : haTask-65296-vim.VirtualMachine.reconfigure-62200

Task : VMware.Vim.ManagedObjectReference

Name : ReconfigVM_Task

DescriptionId : VirtualMachine.reconfigure

Entity : VMware.Vim.ManagedObjectReference

EntityName : VMMACHINE-NAME

Locked :

State : success

Cancelled : False

Cancelable : False

Error :

Result :

Progress : 0

Reason : VMware.Vim.TaskReasonUser

QueueTime : 2/23/2009 9:15:38 AM

StartTime : 2/23/2009 9:15:38 AM

CompleteTime : 2/23/2009 9:15:40 AM

EventChainId : 62200

DynamicType :

Any suggestions??

Thanks, Patrick

0 Kudos