Trying to create script which allows user to specify target PC then accepts user credentials to perform Invoke-Comand on remote PC

by Sep 5, 2014

I'm trying to build a simple script.

1. Allow user to name a target PC

2. Perform registry key deletion on target


If  I run the following strings individually I achieve my objective.

1. $name = Read-Host -Prompt "Please type in the MachineName." 

2. Invoke-Command -cn $name -credential DomainUser {pushd;sl 'HKlM:SYSTEM…'; if(test-path 'Key XYZ'){remove-item ''Key XYZ''}ElSE{"''Key XYZ'' does not exist"};popd}


How do I get these two strings to wait for my input to specify target name: $name, then prompt me for credentials and perform Reg key deletion?

When I run them together I do not get a prompt.