r/PowerShell • • Jul 04 '18

Solved Why does my powershell script stop immediantely after being opened...?

New thread is here: https://www.reddit.com/r/PowerShell/comments/8wceh3/why_does_my_script_work_in_iseps_command_but_not/

It used to work but now it suddently terminates less than a second after being opened. I set the execution policy to unrestricted & re-installed Windows yet it still does not work...

The powershell shows up for 1 second in task manager before windows security health service when it's run using .vbs & then disappears: https://i.imgur.com/VNX7NKx.png

When I paste the script code into PowerShell ISE it works, why is this?

Just to clarify a few things:

The .ps1 file worked with task scheduler (it would load a console window before the message showing up) & when I clicked on the .ps1 file it would also load a console window before the message showed up. When I moved to VB it worked when I clicked on the VB file & when I used the VB file with task scheduler; both without the console window popping up before the message showed.

It still works with VB but only if I create a new user account then after like a day or two it stops working...

Here's what the properties of the task look like (when it worked): https://i.imgur.com/bBIS3od.png

0 Upvotes

78 comments sorted by

View all comments

Show parent comments

5

u/dontridemywave Jul 05 '18

How were you trying to call it? try this?

-7

u/Level-Impression Jul 05 '18

I tried almost every way to call it. None of them work.

3

u/biganthony Jul 05 '18

Put the absolute path of powershell in the text box

Example: c:\program files\powershell.exe (not sure since I'm on mobile)

Then put the command line arguments

Example: -file (insert absolute path to script here)

This works on Windows server 2016 and windows 10

Let me know if this doesn't work. I'll help you out. Whatever it takes to end the use of VB

2

u/Level-Impression Jul 05 '18

I tried that & it doesn't work hence why I moved to VB.

3

u/biganthony Jul 05 '18

So it worked before using task scheduler by itself then stopped working? Then you moved to VB and it worked but stopped working just recently ?

2

u/Level-Impression Jul 05 '18 edited Jul 05 '18

It worked with task scheduler (it would load a console window before the message showing up) & when I clicked on the .ps1 file but it would also load a console window before the message showed up. When I moved to VB it worked when I clicked on the VB file & when I used the VB file with task scheduler; both without the console window popping up before the message showed.

It still works with VB but only if I create a new user account then after like a day or two it stops working...

4

u/biganthony Jul 05 '18

Okay I did some testing with the code you posted. You are running the task with the logged on user correct? You might be sending the notification to a different user session.

In the task settings under security "Run only when user is logged on" is that checked?

Also your username is set under "When running the task, use the following user account:" ?

2

u/Level-Impression Jul 05 '18

I use this: https://i.imgur.com/bBIS3od.png

It's what worked before so I don't think that is the problem...