I am trying to create a PowerShell script that will start/stop services on a remote computer, but prompt the user for all the values. I know the account that will be used; I just need to prompt the user for the password.
This is for Tomcat instances. The problem is the Tomcat service isn't always named the same on different servers (tomcat6, tomcat7). I need to be able to store the password encrypted and prompt to stop or start. Here is what I have so far. Any thoughts?
I am not sure if I have the -AsSecureString
in the right place.
# Prompt for user credentials
$credential=get-credential -AsSecureString -credential Domain\username
# Prompt for server name
$server = READ-HOST "Enter Server Name"
# Prompt for service name
$Service = READ-HOST "Enter Service Name"
gwmi win32_service -computername $server -filter "name='$service'" -Credential'
$cred.stop-service