PS Script working only paste in console or ISE

Lucas Crespo 1 Reputation point
2022-04-06T17:58:14.27+00:00

Hi everyone

Im having some troubles in my script... when i run that at PS ISE he works fine. (same if i paste the code in PS Console)

But, if i run de archive ".ps1" and run by that, nothing happen! i need this for schedule tasks whitout intervention.

My PS Console version is 4.0 and i tried to update to 5.1 but still don't work.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,396 Reputation points
    2022-04-07T00:46:50.207+00:00

    Generate a transcript and also add statements to log start and stop times.

    Start-Transcript -Path C:\Scripts\Logs\MyScript.log
    "$(get-date) - Script is starting." 
    
    # put the rest of your script here
    
    "$(get-date) - Script is ending."
    Stop-Transcript 
    

    Add additional statements in your script at key points in the processing. If you are accessing folders or shares, add in Test-Path or Get-Childitem statements to verify that your script can see the files that it needs to process. Review the MyScript.log file to see what it did.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.