Dlaczego moje skrypty powershell nie są uruchomione?
Napisałem prosty plik wsadowy jako skrypt powershell i dostaję błędy, gdy działają.
Jest w katalogu skryptów w mojej ścieżce.
Cannot be loaded because the execution of scripts is disabled on this system.
please see "get-help about-signing".
Zajrzałem do pomocy, ale to nie jest pomocne. 7 answers
Może być domyślnym poziomem zabezpieczeń PowerShell, który (IIRC) będzie uruchamiał tylko skrypty podpisane.
Spróbuj wpisać to:
set-executionpolicy remotesigned
To powie PowerShell, aby zezwalał na uruchamianie lokalnych (to znaczy na lokalnym dysku) niepodpisanych skryptów.
Następnie spróbuj ponownie wykonać skrypt.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-14 03:41:33
Musisz uruchomić set-executionpolicy:
Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run. Only individual commands may be run.
Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.
Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.
Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run. Warns before running downloaded scripts.
Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.
Mam nadzieję, że to pomoże!Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-21 09:50:41
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Zawsze używaj powyższego cmd
, aby włączyć uruchamianie powershell w bieżącej sesji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-22 07:33:49
Udało mi się ominąć ten błąd, wywołując powershell w ten sposób:
powershell -executionpolicy bypass -File .\MYSCRIPT.ps1
To znaczy, dodałem -executionpolicy bypass
do sposobu, w jaki wywołałem skrypt.
To działało na Windows 7 Service Pack 1. Jestem nowy w powershell, więc mogą być zastrzeżenia do robienia tego, czego nie jestem świadomy.
[edytuj 2017-06-26] nadal używam tej techniki na innych systemach, w tym windows 10 i Windows 2012R2, bez problemów.
Oto, czego teraz używam. To powstrzymuje mnie od przypadkowo uruchamiając skrypt klikając na niego. Kiedy uruchamiam go w schedulerze, dodaję jeden argument: "scheduler" i to omija znak zachęty.To również zatrzymuje okno na końcu, więc mogę zobaczyć wyjście powershell.
if NOT "%1" == "scheduler" (
@echo looks like you started the script by clicking on it.
@echo press space to continue or control C to exit.
pause
)
C:
cd \Scripts
powershell -executionpolicy bypass -File .\rundps.ps1
set psexitcode=%errorlevel%
if NOT "%1" == "scheduler" (
@echo Powershell finished. Press space to exit.
pause
)
exit /b %psexitcode%
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-15 14:02:17
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Powyższe polecenie zadziałało dla mnie nawet wtedy, gdy wystąpi następujący błąd:
Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-08 04:44:48
Warto również wiedzieć, że może być konieczne umieszczenie .\
przed nazwą skryptu. Na przykład:
.\scriptname.ps1
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-08 10:20:10
Polecenie set-executionpolicy unrestricted
pozwoli na uruchomienie dowolnego skryptu jako zalogowanego użytkownika. Pamiętaj tylko, aby ustawić ustawienie executionpolicy z powrotem na signed przy użyciu polecenia set-executionpolicy signed
przed wylogowaniem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-11 19:05:29