PowerShell:运行脚本的执行策略变通方法 [英] PowerShell: Execution policy workarounds to run a script
问题描述
是否有执行政策的解决方法?
Is there a workaround for execution policies?
PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> .\stock.ps1
.\stock.ps1 : File C:\Users\thufir\Desktop\stock.ps1 cannot be loaded because running scripts is disabled on this
system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\stock.ps1
+ ~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\thufir\Desktop>
我只是想找到 股票用脚本引用.是的,你可以通过复制/粘贴来运行脚本,但是......没有任何东西 更好?
I am just looking to find stock quotes with a script. Yes, you can sort of/kind of run a script with copy/paste, but...isn't there anything nicer?
政策如下:
PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
PS C:\Users\thufir\Desktop>
(不是我的机器.)
我正在寻找这个问题的反面.
推荐答案
要构建 Bill_Stewart 的评论,请使用以下目标创建一个快捷方式,它将允许您运行 PowerShell 脚本:
To build off of Bill_Stewart's comment, create a shortcut with the following target and it will allow you to run a PowerShell script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file "\\Server\Path\to\script\script.ps1"
如果你想在远程机器上运行这个命令,你可以在创建上面的快捷方式并将其存储在远程机器可以访问的网络位置之后,始终可以执行这样的操作.
If you want to run this command on a remote machine, you can can always do something like this after creating the above shortcut and storing it somewhere the remote machine can access on the network.
Invoke-Command -computername Computer1 -Scriptblock { Start-process "\\Server\Path\to\shortcut\shortcut.lnk" }
这篇关于PowerShell:运行脚本的执行策略变通方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!