Hi there,
I've been asked by my manager to create a powershell script that will restart the Apache Tomcat service on a remote server located in a different forest.
This will be used by our operations team that do not have domain admin accounts in the event of web services issues at the weekend. I have created an account in the external forest that has permissions to restart services. The Operations team have been give these details.
I would like the script to do the following -
1. Request the engineer to enter the external forest credentials.
2. Request the hostname of the server that's expereincing issues.
3. Restart the tomcat6 service.
4. Check that the service has been restarted and is running.
5. Display a pop-up box indicating that the script has completed successfully or has failed.
Below is a very simple script that I put together. It does restart the service but I'm having trouble getting the script to display a pop-up box indicating that status of the service and weather or not the restart completed successfully.
# This script will restart the Apache Tomcat service on the server specified during the execution
# Prompt for user credential
$credential = get-credential
# Prompt for server name
$server = READ-HOST "Enter Server Name"
# Display service status
$service = gwmi win32_service -computername $server -filter "name='Tomcat6'" -Credential $credential
# Stop service
Write-Host "Service stopping"
$service.StopService() | Out-Null
Start-Sleep -s 10
# Start service
write-host "Service starting"
$service.StartService() | Out-Null
Start-Sleep -s 10
# Diplay service status
$service
Add-Type -AssemblyName System.Windows.Forms
$Form = New-Object system.Windows.Forms.Form
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Tomcat Service has restarted on $server."
$Label.AutoSize = $True
$Form.Controls.Add($Label)
$Form.Visible=$True
Sleep -seconds 10 # do whatever
$Form.Close()
Any help would be greatly appreciated.
Simon