powershell 登录_如何使用PowerShell检测登录并通过电子邮件发出警报

powershell 登录

powershell 登录

The Windows Task Scheduler can automatically send email at a specific time or in response to a specific event, but its integrated email feature won’t work very well for most users.

Windows Task Scheduler可以在特定时间或响应特定事件自动发送电子邮件,但是其集成的电子邮件功能对于大多数用户而言效果不佳。

We have already shown you how to do this using a third party tool, but who really wants to do that when you can do it with tools built right into Windows?

我们已经向您展示了如何使用第三方工具来执行此操作 ,但是当您可以使用Windows内置的工具来执行此操作时,谁真正想这样做呢?

输入PowerShell +任务计划程序 (Enter PowerShell + Task Scheduler)

The first thing we need to do is set up a scheduled task, to do so press the Win + R keyboard combination to bring up a run box then type “control schedtasks” and press enter.

我们需要做的第一件事是设置计划任务,为此,请按Win + R键盘组合以调出运行框,然后键入“ control schedtasks”并按Enter。

image

When the Task Scheduler opens click on the Create Task… link.

当“任务计划程序”打开时,单击“创建任务...”链接。

image

On the General pane, provide a name and description for the task. You should also select the Run whether user is logged on or not option.

在“常规”窗格上,提供任务的名称和描述。 您还应该选择“无论用户是否登录都运行”选项。

image

Then switch over to the Triggers tab and add a new trigger. The trigger should be set to fire at log on, which can be selected from the drop down.

然后切换到“触发器”选项卡并添加一个新触发器。 触发器应设置为在登录时触发,可以从下拉菜单中选择。

image

Finally, you will want to switch over to the actions tab and add a new action. From there, you will want to choose to start a new program, and the program we want this trigger to start is “powershell”. You will then need to paste the following into the arguments text box.

最后,您将要切换到动作选项卡并添加一个新动作。 从那里,您将要选择启动一个新程序,而我们希望此触发器启动的程序是“ powershell”。 然后,您需要将以下内容粘贴到参数文本框中。

-Command “Send-MailMessage -From “someone@gmail.com” -To “someone@gmail.com” -Body “Someone Just Logged In” -Subject “LOGIN”  -SmtpServer “smtp.gmail.com” -Port 587 -Credential $(New-Object System.Management.Automation.PSCredential (someone@gmail.com, $(ConvertTo-SecureString “PASSWORD” -AsPlainText -Force))) –UseSsl”

-命令“ Send-MailMessage-从“ someone@gmail.com”-到“ someone@gmail.com”-身体“刚登录的人”-主题“ LOGIN”-SmtpServer“ smtp.gmail.com”-端口587-凭据$(New-Object System.Management.Automation.PSCredential(someone@gmail.com,$(ConvertTo-SecureString“ PASSWORD” -AsPlainText -Force)))–UseSsl”

Note that you will need to change all occurrences of someone@gmail.com to the username of a real GMail account and PASSWORD to the password for that account. Alternatively, you can opt to use your own SMTP server.

请注意,您需要将所有出现的someone@gmail.com更改为真实GMail帐户的用户名,并将PASSWORD更改为该帐户的密码。 或者,您可以选择使用自己的SMTP服务器。

image

On the Conditions tab, uncheck Start the task only if the computer is on AC power option, or you won’t get emails if your computer is a laptop and it’s unplugged.

在“条件”选项卡上,取消选中“仅当计算机处于交流电源状态时才启动任务”选项,否则,如果计算机是便携式计算机且未拔出电源 ,则不会收到电子邮件。

image

Click the OK button and save your task. You should now receive email notifications whenever someone logs into your computer.

单击确定按钮并保存您的任务。 现在,无论何时有人登录到您的计算机,您都应该收到电子邮件通知。

image

翻译自: https://www.howtogeek.com/141894/how-to-use-powershell-to-detect-logins-and-alert-through-email/

powershell 登录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值