Skip to content

Instantly share code, notes, and snippets.

@daisukenishino2 daisukenishino2/mail.ps1
Last active Jan 16, 2019

Embed
What would you like to do?
ps aux | mail -s ... みたいなことをやるには...
$mail = @{
from = "hoge@hoge-solutions.com";
to = "hoge@hoge-solutions.com";
smtp_server = "smtp.gmail.com";
smtp_port = 587;
user = "hoge@gmail.com";
password = "xxxxxxxx";
}
$password = ConvertTo-SecureString $mail["password"] -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $mail["user"], $password
Send-MailMessage -To $mail["to"] `
-From $mail["from"] `
-SmtpServer $mail["smtp_server"] `
-Credential $credential `
-Port $mail["smtp_port"] `
-Subject "subject" `
-Body ((Get-process) | out-string) `
-Encoding UTF8 `
-UseSsl
@daisukenishino2

This comment has been minimized.

Copy link
Owner Author

commented Jan 16, 2019

実行方法

  • *.ps1ファイルを右クリックしてpowershellで実行。
  • 若しくは、PowerShell ISE or PowerShellコンソールに張り付けて実行。

参考

@daisukenishino2

This comment has been minimized.

Copy link
Owner Author

commented Jan 16, 2019

Body

以下の様な結果が送信されてくる。

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName                                                  
-------  ------    -----      -----     ------     --  -- -----------                                                  
    277      15     3024       3480       0.41   9164   1 AdobeCollabSync                                              
    408      21     5652       7164     172.25  11052   1 AdobeCollabSync                                              
    489      34    55676      24572             18088   0 aspnet_state                                                 
    283      22    22616      38320       0.47    576   1 chrome                                                       
    359      33    68852      96620       6.13   1192   1 chrome                                                       
    ....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.