Michael's profileThe Old Dogs Scripting B...BlogListsNetworkMore ![]() | Help |
|
|
March 12 Check if a Process is running. If not start it and send an Email# COMMENT: Check if Process is running. If not start it and send an Email
# # =======PowerShell Script======================================== if (!(gps myproc -ea 0)) { $MyProcCMD = "c:\program file\my program\myproc.exe /switces" #<-- cmd to start proc $wmi = ([wmiclass]"win32_process").Create($MyProcCMD) if ($wmi.returnvalue -eq 0) { $smtp = new-object system.net.mail.smtpClient("smtp.domain.com") $mail = new-object System.Net.Mail.MailMessage $mail.from = "f...@domain.com" $mail.to.add("t...@domain.com") $mail.subject = "MyProc was in Stopped state. Successfully restarted." $mail.body = "bla-bla-bla" $mail.IsBodyHtml = $true $smtp.send($mail) } Remote Software InventorySo you want to check a server named firefly and see what's installed on it and the version
This script querys the remote computer's uninstall keys and writes out the Display Name and Display version
of everything it finds.
#<----Start PowerShell Script ------->
$computer = "firefly"
$uninstallkey="Software\Microsoft\Windows\CurrentVersion\Uninstall" $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine $remotebase=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$computer) $regkey=$remotebase.OpenSubKey($uninstallkey) $regkey.GetSubKeyNames() | foreach {
$DisName = $remotebase.OpenSubKey("$uninstallkey\$_").GetValue("DisplayName") $DisVer = $remotebase.OpenSubKey("$uninstallkey\$_").GetValue("DisplayVersion") Write-Host $DisName "`t" $DisVer } #<---- End Script --------->
Looking for something more specific? Like Adobe Flash?
#<----Start Script ------->
$computer = "firefly" #<---- End Script ---------> |
|
|