Tried your code and it appears to work fine. What are you having trouble with?
A few notes: If you want to create multiple cubes with this, the name is going to change. To handle this, you can get the object name of the newly created poly cube. Another good practice is to wrap your code in curly braces { // my code } to avoid issues with variable scope.
{
string $myCube[] = `polyCube -w 2 -h 1 -d 2`;
setAttr ($myCube[0]+".rotateY") 45;
setAttr ($myCube[0]+".translateY") 5;
print($myCube); // outputs string array with object name and node name
}