[英]Run PowerShell ISE from the command line?
所以当我从PowerShell ISE运行它时,我有一个可以正常工作的脚本。 但是,我需要自动化它,所以我运行powershell.exe .\\script.ps1
,但是我得到一些未被识别的命令的错误(它们来自非标准模块)。
任何帮助表示赞赏,谢谢!
编辑脚本的开头以导入所有依赖项(模块)。 这是一个很好的做法,因为它使代码更具可读性,适用于PS 2.0和3.0+
script.ps1
#Import example module
Import-Module ActiveDirectory
#Script start
$name = Read-Host "Username"
$user = Get-ADUser $name
.....
一个原因应该是脚本来源或从您的配置文件脚本加载模块。 在这种情况下,您的问题可能来自以下事实:从命令行启动PowerShell并启动PowerShell ISE不会使用系统相同的配置文件脚本。 看看每个中的$Profile
var并编辑相关文件。
$Profile
ISE上的$Profile
:
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
在我的命令行上的$Profile
:
C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
更多关于档案。 About_Profile
一种了解所有$Profile
路径的方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.