Hi Luc,
could yu check the following and suggest how to fix "parameter binding exception" error .
[cmdletbinding()]
param (
[string[]]$esxiname
)
foreach($esxi in $esxiname)
{
$vms=get-vm -Location $esxi|select name
$dsnames=Get-Datastore -RelatedObject $esxi|select name
$prop = {esxiname = $esxi.name
model = $esxi.Model
verison = $esxi.Version
build = $esxi.Build
memorysize = $esxi.MemoryTotalGB
manufectureer = $esxi.Manufacturer}
$obj=New-Object -TypeName psobject -Property $prop
Write-Output $obj
}
error message:
New-Object : Cannot bind parameter 'Property'. Cannot convert the "esxiname = $esxi.name
model = $esxi.Model
verison = $esxi.Version
build = $esxi.Build
memorysize = $esxi.MemoryTotalGB
manufecturer = $esxi.Manufacturer" value of type "System.Management.Automation.ScriptBlock" to type
"System.Collections.IDictionary".
At C:\users\in0079d6\Desktop\Technicolor_script\toolmaking1.ps1:36 char:54
+ $obj=New-Object -TypeName psobject -Property $prop
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.NewObjectCommand
You forgot the @ character when defining the hash table ($prop).
I also added a Get-VMHost cmdlet, since you are passing ESXi hostnames, and the script expects $esxi to hold a HostSystem object.
[cmdletbinding()]
param (
[string[]]$esxiname
)
foreach($esxi in Get-VMHost -Name $esxiname)
{
$vms = Get-VM -Location $esxi | select name
$dsnames = Get-Datastore -RelatedObject $esxi | select name
$prop = @{
esxiname = $esxi.name
model = $esxi.Model
verison = $esxi.Version
build = $esxi.Build
memorysize = $esxi.MemoryTotalGB
manufectureer = $esxi.Manufacturer
}
$obj=New-Object -TypeName psobject -Property $prop
Write-Output $obj
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You forgot the @ character when defining the hash table ($prop).
I also added a Get-VMHost cmdlet, since you are passing ESXi hostnames, and the script expects $esxi to hold a HostSystem object.
[cmdletbinding()]
param (
[string[]]$esxiname
)
foreach($esxi in Get-VMHost -Name $esxiname)
{
$vms = Get-VM -Location $esxi | select name
$dsnames = Get-Datastore -RelatedObject $esxi | select name
$prop = @{
esxiname = $esxi.name
model = $esxi.Model
verison = $esxi.Version
build = $esxi.Build
memorysize = $esxi.MemoryTotalGB
manufectureer = $esxi.Manufacturer
}
$obj=New-Object -TypeName psobject -Property $prop
Write-Output $obj
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks it worked .
$vms and $dsnames are of two different types though both are storing array of objects ,?
Those 2 cmdlets would indeed work with the name of the ESXi node (as a string).
And that is thanks to the Object By Name (OBN) feature that several PowerCLI cmdlets have.
But later on, referring to properties in the $esxi varaible, will only work when that variable holds an actual VMHost object.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i am not using debugging option .but can this missing @ sign before hash table .be validated by any means.the way it does validation in workflows in orchestrator.
Not really, because in both cases you are creating a valid PowerShell expression.
With @{} it is a hash table, with {} it is a code block.
Only when you are executing the New-Object will the error be noticed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaks.