This will help you to create a powershell script to check a running application. If the application is running you will receive an email and if its not running powershell script will start the application. You can copy and make the necessary changes to it and run it with power shell, also you can run it as a scheduled task. Save the script as "anyname.ps1". In this example i am trying to see Outlook is running.
$process = Get-Process -Name "outlook"
$date = Get-Date
if (!$process){
{$_.running -eq $false}
& "C:\Program Files (x86)\Microsoft Office\OFFICE11\outlook.exe"
}
else {
$emailSmtpServer = "smtp.gmail.com"
$emailSmtpServerPort = "587"
$emailSmtpUser = "youremailidhere@gmail.com"
$emailSmtpPass = "yourgmailpasswordhere"
$emailFrom = "youremailidhere@gmail.com"
$emailTo = "youremailidhere@gmail.com"
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.Subject = "Computer started with Axis"
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"
<p>type a message here for you to see on your email.</p>
<p>starting Outlook $date</p>
"@
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )
}
Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts
Tuesday, 10 September 2013
Thursday, 5 September 2013
PowerShell script to kill a not responding task in windows
$notres = Get-Process | Where-Object { $_.responding -eq $false}
$notres.kill()
$notres.kill()
PowerShell script to use ping
$program = "C:\windows\system32\ping.exe"
$programArgs = "192.168.1.1", "-n", 4
Invoke-Command -ScriptBlock { & $program $programArgs }
$programArgs = "192.168.1.1", "-n", 4
Invoke-Command -ScriptBlock { & $program $programArgs }
Wednesday, 4 September 2013
Kill a not responding application from PowerShell
Type the command in a notepad and save it as "name.ps1" and run it with powershell
$notres = Get-Process | Where-Object { $_.responding -eq $false}
$notres.kill()
Subscribe to:
Posts (Atom)