locked
Script is not executing via .\notation but when copy paste on the powershell script on command prompt it working RRS feed

  • Question

  • I have created a script which is generating a windows form and working fine,when i am copy paste the code on powershell prompt but when i am trying to achieve the same using .\powershellscript.ps1  noting is happening .Please suggest 

    Prashant Dev Pandey LIVE IN YOUR OWN WAY Please remember to mark the replies as answers if they help

    Monday, May 27, 2019 11:28 AM

Answers

  • Have you tried to run this with the debugger?

    The code is clearly things you have copied from somewhere.  I recommend that you take some time to learn PowerShell and also learn how the code works.

    The following line is causing you to exit the script:

        continue;

    The issue is caused because you are getting errors that you are not reporting and not handline.

    "continue" from an exception handler in a file causes the file to exit.  It acts like a "return".


    \_(ツ)_/

    Tuesday, May 28, 2019 8:54 AM
  • Just comment out the "continue" statement and it will work like it does when pasted.

    Overall the code handles no exceptions so it is badly designed.  You need to redesign it to manage exceptions correctly.


    \_(ツ)_/

    Tuesday, May 28, 2019 9:11 AM

All replies

  • That is too bad.  What did you put in your script that causes it to not execute?

    Have you tried asking the person who wrote it to help you debug it?

    Remember that dot sourcing does not execute anything.  It just loads the functions.  You still have to call them.


    \_(ツ)_/

    Monday, May 27, 2019 12:42 PM
  • thanks for your inputs

    for example

    when i am trying to load other scripts with dot notation which contains the code for generating the windows form it is working fine . But the piece of code which i have developed it is not  generating the windows form in the same way i am trying to perform the same it is not giving the output not sure what is wrong in my script.  

    powershell.exe ".\powershellscript.ps1" 


    Prashant Dev Pandey LIVE IN YOUR OWN WAY Please remember to mark the replies as answers if they help

    Tuesday, May 28, 2019 7:44 AM
  • Without some idea of what you are doin g it is impossible to help you.

    Please read the following before continuing: How to ask questions in a technical forum


    \_(ツ)_/

    Tuesday, May 28, 2019 8:17 AM

  • Tuesday, May 28, 2019 8:44 AM
  • Have you tried to run this with the debugger?

    The code is clearly things you have copied from somewhere.  I recommend that you take some time to learn PowerShell and also learn how the code works.

    The following line is causing you to exit the script:

        continue;

    The issue is caused because you are getting errors that you are not reporting and not handline.

    "continue" from an exception handler in a file causes the file to exit.  It acts like a "return".


    \_(ツ)_/

    Tuesday, May 28, 2019 8:54 AM
  • Thanks , few function i have copied from internet but i thing it reduces efforts and i have customized according to my requirement not the complete code  .   i ll update shortly post debugging the code.

    Prashant Dev Pandey LIVE IN YOUR OWN WAY Please remember to mark the replies as answers if they help


    Tuesday, May 28, 2019 8:59 AM
  • Just comment out the "continue" statement and it will work like it does when pasted.

    Overall the code handles no exceptions so it is badly designed.  You need to redesign it to manage exceptions correctly.


    \_(ツ)_/

    Tuesday, May 28, 2019 9:11 AM
  • Thanks for your help .Its started working .from the functionality point of view code is working fine.agreed from your point it is badly written .i ll redesign it and include the try catch block. Thanks.you always rock !!!

    Prashant Dev Pandey LIVE IN YOUR OWN WAY Please remember to mark the replies as answers if they help


    Tuesday, May 28, 2019 9:28 AM