该脚本有效。问题在于其他人。双击时会在记事本中打开 .ps1 文件,如果运行,则会引发红色策略警告,并且对于普通用户来说看起来像是恶意软件。将其转换为 EXE 根本与脚本无关——而是与接收它的人有关。
管理员根据代码的功能来判断工具。用户通过点击时发生的情况来判断它们。 Between those two views sits the entire reason script-to-EXE tools exist.如果您曾经通过右键单击,使用 PowerShell 运行,输入 Y,按 Enter 与同事交谈过,而他们则向您读回红色错误文本,那么您已经知道此页面所涉及的问题。
将 .ps1 文件发送给普通用户并观察会发生什么。 They double-click it - and it opens in Notepad, because Windows treats scripts as documents, not programs.什么也没跑。从用户的角度来看,你的工具坏了。
如果他们以某种方式找到“使用 PowerShell 运行”,他们就会遇到执行策略警告,即一堵红色的文本墙,读起来就像病毒警报一样。大多数人都会关闭它并给您打电话。剧本很完美。交付每一步都失败。
That is the whole honest case for converting: it is a kindness to the person on the other end, and it cuts your support calls to near zero.
帮助台交接。您每周运行的修复 - 清除卡住的打印队列、重置配置文件、收集诊断信息 - 成为任何支持同事无需了解 PowerShell 即可运行的文件。
Branch offices and family PCs. People you cannot sit next to get a tool that cannot be run wrong: there is only one way to start an EXE.
Repeated small tools. Anything a user must run more than once deserves a desktop icon, not a path name read out over the phone.
保持诚实的期望。 EXE 不会使脚本更快,不会添加功能,并且不会保护其中的代码 - 源代码可以被读回,这在本集中的其自己的页面中进行了解释。 It also does not remove the need for the script to be correct: a bad script in an EXE is just a bad program that is harder to debug.
And if your audience is other admins, skip the conversion entirely. They can read a script, they distrust black boxes, and for scheduled jobs and Group Policy the plain .ps1 is the right format anyway.
Watch the video for the live conversion and the before-and-after difference for the end user.
Watch Full Video批处理启动器仍然会闪烁控制台窗口,仍然依赖于留在同一位置的 .ps1 文件,并且仍然显示用户脚本机制。 The converted EXE is one self-contained file with its own icon and name, which is what makes non-technical users treat it like a normal program.
一般来说是的,因为用户正在启动一个程序,而不是要求 PowerShell 运行脚本文件 - 这是管理员转换的实际原因之一。您组织自己的应用程序控制策略仍然适用,并且它们应该:这是一个打包工具,而不是隐藏您自己的 IT 规则的策略旁路。
不会。相同的脚本在相同的 PowerShell 引擎上运行; EXE 只包装它。如果说有什么不同的话,那就是包装器准备脚本时的启动成本很小。转换是为了可用性和分发,而不是为了速度。