Hello,
I need a little help with script below.
I want to import a column vm's from a csv file and get the path folder where the vm exist.
Regards,
Harjan
Does this do the trick ?
$ExportFilePath = Get-Date -Uformat "c:\temp\%Y%m%d-Export-VMInfolderpath.csv"
$report = @() $vms = Import-CSV "c:\temp\info.csv"
foreach ($vm in $vms){ $vmView = Get-VM $vm.name | Get-View $row = "" | select Name, Datastore, Path
$row.Name = $vmView.Name $row.Datastore = (Get-View $vmView.Datastore[0]).Summary.Name $current = Get-View $vmView.Parent $path = $vmView.Name do { $parent = $current
if($parent.Name -ne "vm"){
$path = $parent.Name + "\" + $path
} $current = Get-View $current.Parent } while ($current.Parent -ne $null) $row.Path = $path
$report += $row
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Thank you for answer.
I get the follow error
What is the layout of your CSV file ?
It should be like this
"Name"
"vm1"
"vm3"
"vm3"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Name |
NLSIVM539 |
NLSIVM530 |
NLSIVM266 |
The only explanation I can see, is that there must be 1 or more blank lines in the CSV file.
Can you check ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, that works.
If I added a blank line the script runs successfully. When I removed the blank line the scripts runs now also.
Thanks!