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

2

u/Level-Impression Jul 05 '18

I used this but it doesn't work in a .ps1 though it works in ISE: https://pastebin.com/PTbqnRUZ

1

u/Lee_Dailey [grin] Jul 05 '18

howdy Level-Impression,

now that is so very odd. [frown]

i added a pause at the to a new line at the end of your new script.

here's what seems to be happening ...

  • run it from the ISE
    works as expected.

  • run it from the powershell.exe console
    runs the script and pauses but NO balloon tip ever shows.

i suspect that there is something about the way the ISE is written that is loading something differently.

but i have no freaking idea what that could be. [sigh ...]

i would mark this thread with a solved flair AND add a msg to your original post that there is a new thread on the narrower situation. pro'ly otta add a link to that new thread once you make it.

then create a new thread. use the question flair that shows up after you have created the post. it's on the bottom of the post next to the crosspost and other link-buttons.

i think you have narrowed things down enuf to justify a new thread without all the distraction of the VBScript and task scheduler stuff.

you have found a VERY specific glitch and i would make a new thread on ONLY that. add a link back to this thread for completeness - but focus on the actual now-identified problem. leave out the vbs & task scheduler stuff entirely.

don't give in to the temptation to expand the question, either! [grin] stay focused on the known specific glitch. once that is fixed, then you can start another thread on how to get it to work as you want.

keep it as simple as possible.

take care,
lee

2

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

Before I make the new thread something weird happened again. When I right click my script & click 'Run with powershell' I get this (but not when I double click the .ps1 file): https://i.imgur.com/LZ5PPNd.png

This only happened after I put my script (the original one not https://pastebin.com/PTbqnRUZ) in the PS command (where it worked) + the icon on my script changed to this: https://i.imgur.com/UtH3zxg.png

1

u/Lee_Dailey [grin] Jul 05 '18 edited Jul 05 '18

howdy Level-Impression,

oooo! that looks like it may have some impact. [grin]

if you are not running this on a personal system, i would talk to your admin folks about recent changes. especially security & group policy stuff.

if this is a personal system, then i would start checking for recent windows updates. MS has taken the nasty step of changing things with very little warning - especially when dealing with non-enterprise setups. [sigh ...]

i use win7 on a single rather old system at home. i've no access at all to anything else. that means i am not going to be much use going forward on this. [sigh ...]

take care,
lee

2

u/Level-Impression Jul 05 '18

In the local security policy my account has permission to 'Log on as a batch job' + I've enabled script execution to unrestricted via group policy. The script didn't stop working after a windows update + whenever I do get an update it ends up uninstalling as my PC is really old so I don't think that is the issue (Dell computer made in 07/08).

2

u/biganthony Jul 05 '18

Are you able to post the full script?

Also read this: https://blogs.technet.microsoft.com/christwe/2012/09/20/but-i-ran-set-executionpolicy-unrestricted-what-is-going-on/

The script is attempting to set the execution policy to bypass but it cant because of your group policy

1

u/Lee_Dailey [grin] Jul 05 '18

howdy Level-Impression,

how very odd! [grin] usually that message reflects a conflict with a GPO setting. if you see it again, then i think you may want to start digging - and possible open a new thread on just that problem.

again, you are beyond anything i know. [sigh ...]

take care,
lee