Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Import from CSV to snapshot VMs

$
0
0

Hi guys, I'm really new to powershell and I'm trying to do something fairly simple. I have a CSV file which contains the names of a couple of VMs I want to snapshot.

Here is my code

Add-PSSnapin "VMware.VimAutomation.Core"
connect-viserver 192.168.1.162 -user root -password password

$VMs_to_snap=import-csv c:\temp\test.csv
foreach ($VM in $VMs_to_snap) {
get-vm -name $VM | new-snapshot -name test_snap
}

It looks like the problem is that it's including the header of the CSV along with the VM name but I don't know how to strip that out. It errors out saying that the name was not found. Instead of sending VM3 as the name, it's sending VM Name=VM3 (in bold below).

 

get-vm : 13/09/2014 6:55:35 PM    Get-VM        VM with name '@{VM Name=VM3}' was not found, using the specified filter(s).   
At C:\temp\snapshot_vm_from_csv.ps1:14 char:1
+ get-vm -name $VM | new-snapshot -name test_snap
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-VM], VimException
    + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

 

How do I get it so it doesn't include the header and only sends the name?


Viewing all articles
Browse latest Browse all 6937

Trending Articles