VMware Cloud Community
Paulk99
Enthusiast
Enthusiast
Jump to solution

Power Cli Question....

Hi All

Ive been trying to use powercli to set the "All Guest Memory Locked Feature"against a group of servers, specified in a CSV file.

However im not getting any luck in having it run for the group of servers ive listed out in the CSV.

Ive been able to set against one Named VM using the thread 427969 on here.

Not sure where im going wrong on this one any help greatly appreaciated.

P

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I hadn't noticed that the method you used was ReconfigureVM_Task.

That should be ReConfigVM_Task.

The corrected code is (I also took the constant part outside the loop)

$guestconfig = New-Object VMware.vim.VirtualMachineConfigSpec

$guestconfig.MemoryReservationLockedtoMax = $true


$VMList = Import-CSV "Path to CSV" -UseCulture


foreach ($VM in $VMList) {

   (Get-VM -Name $VM.VMNames).ExtensionData.ReconfigVM_Task($Guestconfig)

}


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

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

Can you show us the script your are using, and also your CSV file?


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

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Hiya

(Where VMNames is the headding of the coloum in my .CSV file)

$VMList = Import-CSV "Path to CSV" -Use Culture

foreach($VM in $VMList)

$guestconfig = New-Object VMware.vim.VirtualMachineConfigSpec

$guestconfig.MemoryReservationLockedtoMax = $ true

(GetVM VMNames.ExtensionData.ReconfigureVM_Task($Guestconfig)

Sorry i know its a pretty simple and im a ways out one but ive not put my scripting head on for ages !!! Smiley Happy

Cheers

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are a few minor issues in the code.

Try like this

$VMList = Import-CSV "Path to CSV" -UseCulture

foreach ($VM in $VMList) {

   $guestconfig = New-Object VMware.vim.VirtualMachineConfigSpec

   $guestconfig.MemoryReservationLockedtoMax = $true


   (Get-VM -Name $VM.VMNames).ExtensionData.ReconfigVM_Task($Guestconfig)

}


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

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Cheers Sir

Will give it a go Tomorrow when Im back in..!

P

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Hi There,

Sorry its still really unhappy with that last line of code when i run it through PowerCLI.

It errors with.

Get-VM : Cannot validate argument on paramater "Name" . The argument is null or empty. Provide an argument that is not Nul or Empty and then try the command again.

At Line:4 Char:15

(Output of line 4 of code)

               + Category Info      : InvalidData: (:) [Get-VM] , ParamaterBindingValidationException

               + Fully QualifiedError ID     : ParamaterArgumentValidation Error,Vmware.VimAutomation.VICore.Cmdlets.commands.GetVM 

I will Keep digging, Please let me know if you have any further thoughts.

P

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Looks like the column header in your CSV is not VMNames.

Can you show part of your CSV file?


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

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Difficult as its airgapped let me recreate it for you (i have now attached.

The only difference in the script as shown is the lines to connect to vCenter (which is sucessfull)

If its any help the error is now down to

You cannot call a method on a null-valued expression

Line 4 char 1

Category info           : Invalid Opperation (:) [], runtime exception

Fully qualified error ID : InvokeMethod on Null

I know this works on an individual Server as when i replace -Name $VM.VMnames for an actual server name the action was completing.

I just cant get it to work through the .CSV to apply to myltiple servers grrrr Smiley Happy

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I hadn't noticed that the method you used was ReconfigureVM_Task.

That should be ReConfigVM_Task.

The corrected code is (I also took the constant part outside the loop)

$guestconfig = New-Object VMware.vim.VirtualMachineConfigSpec

$guestconfig.MemoryReservationLockedtoMax = $true


$VMList = Import-CSV "Path to CSV" -UseCulture


foreach ($VM in $VMList) {

   (Get-VM -Name $VM.VMNames).ExtensionData.ReconfigVM_Task($Guestconfig)

}


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you attach the actual script you are using?


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

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Hiya.

Still dosnt like that last line.. but looks like its getting closer.

You cannot call a method on a null-valued expression.

At line:3 char:1

(Get-VM -Name $VM.VMNames).ExtensionData.ReConfigVM_task($guestconfig)

+ Category Info                :Invalid Opperation (:)  {}, RuntimeException

+ FullyQualifiedErrorID     :InvoveMethodOnNull

The script performs no other function other than authentication to Vcenter which i have already tested and that is working as expected.

this is the complete script outside of that.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you just run the following?

Import-CSV "Path to CSV" -UseCulture


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

Reply
0 Kudos
Paulk99
Enthusiast
Enthusiast
Jump to solution

Call off the dogs sir..... !

I had made a slight spelling error on the retype (if we were not airgapped i could have coppied and pasted directly) !

Looks like it playing ball now many many thanks indeed.

Kind Regards

Reply
0 Kudos