$changename=$pcname.text
function namechange {
Rename-Computer -NewName "$pcname.text" -Restart
}
$pcname.text is a textbox where I manually put the PC name, after that I click a button so the nameChange starts. The computer isn't in a domain and the I'm logged in as a local admin. When I run my code it still returns "Access denied". When I google the Rename-Computer command it says I should be able to edit it just like the above code.
What did I do wrong? Can someone help me with some proper code or fix the above?