I’ve tried already to change name parameter with $($i) or “$($I)”. Also can someone please explain why sometimmes is neccessary to use $($i) instead of $i.
“The object name has bad syntax”
Looking at your script, you´re not using the variable you created on the second line (-Name $i should be -Name $nicnkame). As for the -Otherattributes hashtable, the values should probably be strings, so “$i” or “$($i)”, in this case either should work (if $i already is a string “” is not needed). In a string $() tells powershell that what´s inside is a variable or function that needs to be resolved. If $i had multiple values, and you just wanted the value for name, in a string “$i.name” would not work. The .name would be red as a string, you would need to use “$($i.name)”.