Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

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

$
0
0

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 Domain\User {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.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles