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

6

u/Ta11ow Jul 04 '18

Why are you running it with vbs?

-5

u/Level-Impression Jul 04 '18

So I can use it with task scheduler. It doesn't run if I just try to open the .ps1 file.

0

u/[deleted] Jul 04 '18

[deleted]

-12

u/Level-Impression Jul 05 '18

I did & it didn't work.

4

u/Theratchetnclank Jul 05 '18

Asks for help. Doesn't like the answer so shuts it down.

Love it.

0

u/Level-Impression Jul 05 '18

Shuts down what?

0

u/[deleted] Jul 05 '18

[deleted]

1

u/Level-Impression Jul 05 '18

It didn't but now I did & it still doesn't work. It used to work before so that can't be the problem.

0

u/[deleted] Jul 05 '18

[deleted]

1

u/Level-Impression Jul 05 '18

How do I check? I'm new to PS so thanks for being patient.

0

u/[deleted] Jul 05 '18

[deleted]

2

u/Level-Impression Jul 05 '18

It shows the time in which the task was scheduled to run.

→ More replies (0)

3

u/devperez Jul 05 '18

I've done it multiple times. There was something I had to do, but I forget exactly. But I remember Googling it and it worked out easily enough.

2

u/[deleted] Jul 05 '18

then you did it wrong. i have done this hundreds of times. see below for a snippet of the exported task in XML.

<Actions Context="Author">

<Exec>

<Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>

<Arguments>-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -File "C:\Scripts\Script.ps1"</Arguments>

</Exec>

</Actions>

0

u/Level-Impression Jul 05 '18

I tried that & it does not work...

2

u/[deleted] Jul 05 '18

You're doing something wrong then.

0

u/Level-Impression Jul 05 '18

It worked before so clearly I was doing something right...

2

u/[deleted] Jul 05 '18

can you post the sanitized version XML export of the task?