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。
When the Task Scheduler opens click on the Create Task… link.
当“任务计划程序”打开时,单击“创建任务...”链接。
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.
在“常规”窗格上,提供任务的名称和描述。 您还应该选择“无论用户是否登录都运行”选项。
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.
然后切换到“触发器”选项卡并添加一个新触发器。 触发器应设置为在登录时触发,可以从下拉菜单中选择。
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服务器。
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.
在“条件”选项卡上,取消选中“仅当计算机处于交流电源状态时才启动任务”选项,否则,如果计算机是便携式计算机且未拔出电源 ,则不会收到电子邮件。
Click the OK button and save your task. You should now receive email notifications whenever someone logs into your computer.
单击确定按钮并保存您的任务。 现在,无论何时有人登录到您的计算机,您都应该收到电子邮件通知。
翻译自: https://www.howtogeek.com/141894/how-to-use-powershell-to-detect-logins-and-alert-through-email/
powershell 登录