Try like this
Get-Contentt c:\Script\adddisk.txt | %{
$hostname = Get-VM -Name $_ | Get-VMHost | Select -ExpandProperty Name
if($hostname -eq "esx3"){
$dsname = "Datastore3"
}
elseif($hostname -eq "esx4"){
$dsname = "Datastore4"
}
New-HardDisk -VM $_ -CapacityGB 5 -DiskType Flat -Datastore $dsname -StorageFormat Thin
}
The Get-Content will read the file line by line.
We execute the codeblock for each line (the ForEach construct - the alias is %)
Testing on equality of strings is done with the -eq operator, the = operator is only used for assignments.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference