VMware Cloud Community
max08
Contributor
Contributor

Script to increase memory via CSV file

I have tried this numerous ways with no luck whatsoever.  Can someone help me out?

I recently upgrade powercli to 5.5 if that matters.  This is the script:

$csv=Import-CSV memory.csv

foreach($vm in $csv){

Get-VM $($vm.server) |

Set-VM $vm -MemoryGB -8 -Confirm:$False |

}

The contents of the csv file is a single column row 1 is server and row 2 is the vm I want to increase the memory on.

It fails with this message (in fact many of my previous working scripts are failing with this message)

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not nu

ll or empty and then try the command again.

At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\powerCLI\working_scripts\csv\memory.ps1:4 char

:8

+  Get-VM <<<<  $($vm.server) |

    + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Can someone help me out? 

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try like this

$csv=Import-CSV memory.csv -UseCulture

foreach($vm in $csv){

    Get-VM $vm.server |

    Set-VM $vm -MemoryGB -8 -Confirm:$False

}

And to make sure, your CSV looks like this

server

VM1

VM2


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

0 Kudos