hi Luc,
can you please suggest what is wrong in following .it used to work fine numerous times in past but for some reasons not today.
$vms_info=Import-Csv -Path "c:\users\user1\desktop\folder1\vmnames.csv"
$vms.count
foreach ($line in $vms_info)
{
$vma=get-vm $line.vmname
$vma|select name
}
iam getting folowing
There could be an issue in the CSV file.
Does the 1st line contain the headers?
Is the column actually called vmname?
Is there a blank line in the CSV?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
well i used it many times in past so i checked all what yu asking .
it is something like this
vmname
vm1
vm2
vm3
vm4
vm5
however what actually i am looking is to add provisionedspace of vms provided by csv file .
thanks
Is the error gone then?
There is not really a point in adding functionality when the basic loop is not working.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The snippet of script works fine unless the first line of the CSV is blank.
Then I see the error the OP describes.
I think I mentioned the blank line in my earlier reply.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So you did! :smileyblush:
What wasn't mentioned was any errors or warnings raised before the one mentioned. I believe the import-csv commandlet will say :
"WARNING : one or more headers were not specified. Default names starting with "H" have been used in placed of any missing headers."
So should have been easy spot, if that was the actual case.
it has not gone .howevereverthing seems correct .
also $vms_info variable has following
Can you run this
$vms_info.Count
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i tried that its giving me 5 .
Now try
ForEach-Object -Process {
Get-VM -Name $_.vmname | select Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i thought of doing this way wherein we need to input vms.all i need is to add provisioned space of each vm .
can you pleasemodifyorange code in simplest wat to get sum of provisioned space .
$strings = @()
do {
$answer = Read-Host -Prompt "Enter a substring (blank to end)"
if($answer){
$strings += $answer
}
} until ($answer -eq '')
for ($i=0; $i -lt $strings.Length; $i++)
{
$vm=get-vm -Name $strings[$i]
$vm|select name,provisionedspacegb
$sum=0
$final_sum=$sum+$vm.ProvisionedSpaceGB
}
Before we go any further, is the CSV and the loop working now?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
for some wieredreasons it is not however in the mean time i figured out the following way and it is working.however iam checking the csv and foreach loop one more time .
$strings = @()
do {
$answer = Read-Host -Prompt "Enter a substring (blank to end)"
if($answer){
$strings += $answer
}
} until ($answer -eq '')
$fragments = @()
for ($i=0; $i -lt $strings.Length; $i++)
{
$vm=get-vm -Name $strings[$i]
$vm|select name,provisionedspacegb
#$sum=0
$provisionedspacegb=$vm.ProvisionedSpaceGB
$provround=[math]::Round($provisionedspacegb)
$fragments += $provround
}
$sum = $fragments -join '+'
Invoke-Expression $sum
So your question is answered?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
well in some other way iam still checking why the csvthing does not work .