Hi
I have several Annotations I want to add to a VM using Powercli, and a csv
In the csv I have
CustomeAttribute,Value
Customisation,Win10
IP,192.168.0.1
In the script
$attributes = Import-Csv C:\CustomAttribute.csv -Header ("CustomAttribute","Value")
foreach ($attribute in $attributes){
Set-Annotation -Entity VMNAME -CustomAttribute $_.CustomAttribute -Value $_.Value
}
I keep getting an error
Set-Annotation : Cannot validate argument on parameter 'CustomAttribute'. The argument is null. Provide
a valid value for the argument, and then try running the command again.
Can anyone help please?
Thanks
Try your loop like this
foreach ($attribute in $attributes){
Set-Annotation -Entity (Get-VM -Name VMNAME) -CustomAttribute $attribute.CustomAttribute -Value $attribute.Value
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try your loop like this
foreach ($attribute in $attributes){
Set-Annotation -Entity (Get-VM -Name VMNAME) -CustomAttribute $attribute.CustomAttribute -Value $attribute.Value
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked perfectly..
So, calling attribute.customattribute pulls that data from the row in the CSV?
Thanks
You already imported the content of the CSV in the array $attributes.
Then with the ForEach loop you take the content of that array row by row, and each row is stored in the variable $attribute.
Each column in the CSV is a property on each row object, and you retrieve the values of the two columns by addressing the properties $attribute.CustomAttribute and $attribute.Value
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great explanation, thanks