Skip to main content

I wrote this worklet at the request of one of our customers. They want to pop open a browser window to a survey site every morning for their users. To edit this for your use case, all you need to do is replace the URL in the $command variable, and to make sure that Powershell is allowed to run scripts on the endpoint as a user. This is because it’s making use of the scheduled task feature to run the worklet as the logged in user instead of System. To do that, you can run this command (as admin) on the endpoint:


`Set-ExecutionPolicy RemoteSigned’



Evaluation code:



Exit 1



Remediation code:



$time = (Get-Date).AddSeconds(5)

$triggerAt = New-ScheduledTaskTrigger -At $time -Once

$currentusr = (Get-WmiObject -class win32_process -ComputerName 'localhost' | Where-Object name -Match explorer).getowner().user

$command = "start https://www.google.com"



New-Item -Path "c:\ProgramData\Amagent" -Name "message.ps1" -ItemType "file" -Value $command



$action = New-ScheduledTaskAction -Execute Powershell.exe -Argument "-windowstyle hidden c:\ProgramData\Amagent\message.ps1"



Register-ScheduledTask -TaskName "StartMsg" -Trigger $triggerAt -Action $action -User $currentusr

Start-Sleep 6

Unregister-ScheduledTask -TaskName "StartMsg" -Confirm:$false

Remove-Item -Path "c:\ProgramData\Amagent\message.ps1"

Be the first to reply!

Reply