none
Problem running a powershell script on Server2008

    Pertanyaan

  • I have a script that references another PS script that deletes a bunch of files in some folders.  Both files are in the same folder.  When I run my script, it works fine and the files are deleted from the folders as desired.  However, if I try it from the Run command or from within task scheduler, it doesn't run.  I triple checked and the execution policy is set to unrestricted.

    I have been beating my head against the wall for hours, trying every possible combination and am at the end of my rope for today.  I'm exceedingly new to Powershell and would deeply appreciate any help.

    The error I get is:

    The term '.\deleteold.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program....

    At C:\users\user_name\folderpurge.ps1:1 char: 16

    + .\deleteold.ps1 <<<<  -folderpath c:\users\user_name\testfolder -fileage 1 -logfile c:\users\user_name\scanpurgelog.txt -NoFolder

              +CategoryInfo              :ObjectNotFound: (.\deleteold.ps1:String)  [], CommandNotFoundException

               +FullyQualifiedErrorID  :CommandNotFoundException

    • Dipindahkan oleh Bill_Stewart Jumat, 31 Oktober 2014 16.52 Abandoned
    Jumat, 22 Agustus 2014 18.25

Semua Balasan

  • Hi 

    If you set the execution policy to remote assigned what happens?


    Hope this helps. Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Jumat, 22 Agustus 2014 18.46
  • Same thing.  here's what I'm launching from Start |Run

    C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe -noexit "c:\users\user_name\folderpurge.ps1"

    I also tried:  powershell.exe -noexit "c:\users\user_name\folderpurge.ps1"  same result

    I also tried:  powershell.exe -noexit c:\users\user_name\folderpurge.ps1 same result

    I also tried:  powershell.exe -noexit -file c:\users\user_name\folderpurge.ps1 same result

    When I attempt to run inside of PowerShell ISE, I get the message the deleteold.ps1 is not digitally signed and will not execute on the system.  When I set it to unrestricted, I get a security warning, can click Run Once and the script works fine.


    • Diedit oleh agghopp Jumat, 22 Agustus 2014 20.42 clean up
    Jumat, 22 Agustus 2014 19.18
  • The error message is pretty explicit.  THe scritp tha tis being called has issues.

    Where is "deleteold.ps1" stored.  Is it on a network share?  Rememebr that you are "remote signed"  NOT REMOTE ASSIGNED.

    A script on a share is "remote" and must be signed.


    ¯\_(ツ)_/¯

    Jumat, 22 Agustus 2014 20.29
  • Both the folderpurge.ps1 and deleteold.ps1 files are located on the file server's C: drive (for now).  They are sitting next to each other in:

                       c:\users\user_name\folderpurge.ps1

    The folders and subfolders are in   c:\users\user_name\testfolder

    Jumat, 22 Agustus 2014 20.42
  • The error message is pretty explicit.  THe scritp tha tis being called has issues.

    Where is "deleteold.ps1" stored.  Is it on a network share?  Rememebr that you are "remote signed"  NOT REMOTE ASSIGNED.

    A script on a share is "remote" and must be signed.


    ¯\_(ツ)_/¯

    When you say I am remote signed, not remote assigned, are you telling me to modify the execution policy?  Thanks for your insight.


    Greg

    Jumat, 22 Agustus 2014 20.44
  • The error message is pretty explicit.  THe scritp tha tis being called has issues.

    Where is "deleteold.ps1" stored.  Is it on a network share?  Rememebr that you are "remote signed"  NOT REMOTE ASSIGNED.

    A script on a share is "remote" and must be signed.


    ¯\_(ツ)_/¯

    When you say I am remote signed, not remote assigned, are you telling me to modify the execution policy?  Thanks for your insight.


    Greg

    There is no such thing as remote "assigned"  Be sure you are set to RemoteSigned:

    PS C:\scripts> Get-ExecutionPolicy
    RemoteSigned

    The error also may indicate that you have another issue with the file.  Be sure it is not blocked.

    Unblock-File c:\users\user_name\folderpurge.ps1


    ¯\_(ツ)_/¯

    Jumat, 22 Agustus 2014 22.47
  • I was able to execute it with the following steps:
    1. Run CMD
    2. CD "folder where the script is"
    3. Powershell.exe -command "Set-ExecutionPolicy -ExecutionPolicy UNRESTRICTED"
    4. PowerShell.exe -Command " .\deleteold.ps1 -FolderPath D:\temp\prueba -FileAge 30 -LogFile D:\temp\prueba -AutoLog -VerboseLog -ListOnly"
    Rabu, 21 November 2018 20.26